Rapando commited on
Commit
bdd6e15
·
1 Parent(s): 1781ce4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis and named entity recognition pipelines from Hugging Face Transformers
5
+ sentiment_analyzer = pipeline('sentiment-analysis')
6
+ ner_analyzer = pipeline('ner')
7
+
8
+ # Function to perform multiple analyses on text
9
+ def analyze_text(text):
10
+ # Sentiment analysis
11
+ sentiment_result = sentiment_analyzer(text)[0]
12
+ sentiment_analysis = f"Sentiment: {sentiment_result['label']} ({sentiment_result['score']:.2f})"
13
+
14
+ # Named Entity Recognition (NER)
15
+ ner_results = ner_analyzer(text)
16
+ ner_analysis = "Named Entities:\n" + "\n".join([f"{entity['word']} ({entity['entity']})" for entity in ner_results])
17
+
18
+ return sentiment_analysis + "\n\n" + ner_analysis
19
+
20
+ # Create a Gradio interface
21
+ iface = gr.Interface(fn=analyze_text, inputs="text", outputs="text")
22
+
23
+ # Launch the Gradio app
24
+ iface.launch()
25
+
26
+