samiNCL commited on
Commit
d594d7c
1 Parent(s): 94c435e
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # Sami Alghamdi 21 May 2023
2
  import pandas as pd
3
  import spacy
4
  import gradio as gr
@@ -6,6 +5,10 @@ from nrclex import NRCLex
6
  from transformers import pipeline
7
  from rake_nltk import Rake
8
  import io
 
 
 
 
9
 
10
  # Initialize objects
11
  emotion_pipeline = pipeline('sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment')
@@ -19,14 +22,14 @@ def process_csv(file):
19
  entities = []
20
  keywords = []
21
  for _, row in df.iterrows():
22
- text = row['Content'] # Replace 'Content' with the correct column name
23
  nrc_obj = NRCLex(text)
24
  emotion_scores = nrc_obj.affect_frequencies
25
  emotions.append(emotion_scores)
26
  sentiment = analyze_emotion(text)
27
  sentiments.append(sentiment)
28
  entities.append(analyze_entities(text))
29
- keywords.append(extract_keywords(text)) # Extract keywords for each text
30
 
31
  df['emotions'] = emotions
32
  df['sentiment'] = sentiments
@@ -47,7 +50,7 @@ def analyze_entities(text):
47
 
48
  def extract_keywords(text):
49
  rake.extract_keywords_from_text(text)
50
- return rake.get_ranked_phrases() # Extract keywords from text
51
 
52
  iface = gr.Interface(fn=process_csv, inputs=gr.inputs.Textbox(lines=13, label="Paste CSV Here"), outputs="text")
53
  iface.launch()
 
 
1
  import pandas as pd
2
  import spacy
3
  import gradio as gr
 
5
  from transformers import pipeline
6
  from rake_nltk import Rake
7
  import io
8
+ import spacy.cli
9
+
10
+ # Download the spaCy model
11
+ spacy.cli.download("en_core_web_sm")
12
 
13
  # Initialize objects
14
  emotion_pipeline = pipeline('sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment')
 
22
  entities = []
23
  keywords = []
24
  for _, row in df.iterrows():
25
+ text = row['Content']
26
  nrc_obj = NRCLex(text)
27
  emotion_scores = nrc_obj.affect_frequencies
28
  emotions.append(emotion_scores)
29
  sentiment = analyze_emotion(text)
30
  sentiments.append(sentiment)
31
  entities.append(analyze_entities(text))
32
+ keywords.append(extract_keywords(text))
33
 
34
  df['emotions'] = emotions
35
  df['sentiment'] = sentiments
 
50
 
51
  def extract_keywords(text):
52
  rake.extract_keywords_from_text(text)
53
+ return rake.get_ranked_phrases()
54
 
55
  iface = gr.Interface(fn=process_csv, inputs=gr.inputs.Textbox(lines=13, label="Paste CSV Here"), outputs="text")
56
  iface.launch()