Ver Fonte

Merge pull request #1028 from Paulie-Aditya/patch-1

Hackathon Submission
Marine Gosselin há 1 ano atrás
pai
commit
1931187c73

+ 17 - 0
Quine Package Quests/Movie-Analysis-Taipy/README.md

@@ -0,0 +1,17 @@
+<h1>Welcome to Movie Analysis and Review System!</h1>
+
+To use this application on your own device:
+
+➣ Clone this repo
+➣ Install the requirements
+➣ Run main.py
+➣ Congratulations! You can now use the Application!
+
+You would be able to find out the Sentiment of Any Movie available on IMDb!
+
+
+Here, BeautifulSoup has been used for Scraping the data from IMDb to fetch authentic user reviews. A Sentiment Analyzer is then used on these reviews to find out what the overall sentiment of the movie is.
+
+This Sentiment and the Confidence is then sent to the frontend and using Taipy, the final output is shown back to the user.
+
+

+ 32 - 0
Quine Package Quests/Movie-Analysis-Taipy/main.py

@@ -0,0 +1,32 @@
+from taipy.gui import Gui, notify
+import taipy.gui.builder as tgb
+from script import sentiment_analysis
+
+text = "Original text"
+
+def on_button1_action(state):
+    data = sentiment_analysis(state.text, language="English")
+    notify(state, 'info', f'Sentiment: {data["sentiment"]} , Confidence: {data["percentage"]}')
+    return
+
+def on_button2_action(state):
+    data = sentiment_analysis(state.text, language="Hindi")
+    notify(state, 'info', f' भाव: {data["sentiment"]} , भरोसा: {data["percentage"]}')
+    return
+
+
+# Definition of the page
+with tgb.Page() as page:
+
+
+    tgb.text("Movie Analysis and Review System!", class_name="h1")
+
+    tgb.text("Enter a Movie Name", class_name="h6")
+
+    tgb.input("{text}")
+
+    tgb.button("Search to get Results in English!", on_action=on_button1_action, )
+    
+    tgb.button("Search and Get Results in Hindi!", on_action=on_button2_action)
+
+Gui(page).run(port=1000)

+ 5 - 0
Quine Package Quests/Movie-Analysis-Taipy/requirements.txt

@@ -0,0 +1,5 @@
+taipy
+requests
+BeautifulSoup4
+nltk
+cinemagoer

+ 78 - 0
Quine Package Quests/Movie-Analysis-Taipy/script.py

@@ -0,0 +1,78 @@
+import re
+import requests
+from bs4 import BeautifulSoup
+import sentiment
+from imdb import Cinemagoer
+
+
+def fetch_movie(input):
+    ia = Cinemagoer()
+
+    search = ia.search_movie(title=input)
+
+
+    if(len(search)==0):
+        print("Not Found")
+
+    id = "tt"+search[0].movieID
+    data = search[0].data
+    title = data['title']
+    poster_url = data['cover url']
+    url = f'https://www.imdb.com/title/{id}/reviews/'
+    return url, title, poster_url
+
+
+def html_removal(text):
+   text = re.compile(r'<[^>]+>').sub('', text)
+   return text
+
+def reviews_func(url):
+    
+    page = requests.get(url=url)
+
+    soup = BeautifulSoup(page.content, "html.parser")
+
+    reviews = soup.find_all("div",class_="text show-more__control")
+    reviews = list(reviews)
+    for i in range(len(reviews)):
+        reviews[i] = html_removal(str(reviews[i]))
+    return reviews
+
+def sentiment_analysis(movie, language = "English"):
+    analysis = dict()
+    url, title, poster_url = fetch_movie(movie)
+    analysis['title'] = title
+
+    reviews = reviews_func(url)
+    total = len(reviews)
+    positive = 0
+    negative = 0
+    for review in reviews:
+        score = sentiment.calc_score(str(review))
+        if score == 'Positive':
+            positive+=1
+        elif score == 'Negative':
+            negative+=1
+    
+    if(positive>negative):
+        overall_sentiment = 'Positive'
+        percentage = f"{round((positive/total),2)*100}%"
+    elif(positive<negative):
+        overall_sentiment = 'Negative'
+        percentage = f"{round((negative/total),2)*100}%"
+    else:
+        overall_sentiment = 'Neutral'
+        percentage = "50%"
+    
+    analysis['sentiment'] = overall_sentiment
+    analysis['percentage'] = percentage
+
+    if(language == "English"):
+        return analysis
+    elif(language == "Hindi"):
+        if(analysis['sentiment'] == "Positive"):
+            analysis['sentiment'] = 'उत्तम'
+        elif(analysis['sentiment'] == "Negative"):
+            analysis['sentiment'] = 'खराब'
+
+    return analysis

+ 18 - 0
Quine Package Quests/Movie-Analysis-Taipy/sentiment.py

@@ -0,0 +1,18 @@
+import nltk
+#nltk.download('punkt')
+#nltk.download('vader_lexicon')
+
+
+
+from nltk.sentiment.vader import SentimentIntensityAnalyzer 
+
+sia = SentimentIntensityAnalyzer()
+
+def calc_score(text:str):
+    score = sia.polarity_scores(text)
+    if(score['compound']>=0.05):
+        return "Positive"
+    elif(score['compound']<0.05 and score['compound']>-0.05):
+        return "Neutral"
+    else:
+        return "Negative"