vinayarni commited on
Commit
63b8f61
·
verified ·
1 Parent(s): 0abac7b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install dependencies if not already installed
2
+ # !pip install gradio transformers
3
+
4
+ import gradio as gr
5
+ from transformers import pipeline
6
+
7
+ # Load sentiment analysis pipeline
8
+ pipe = pipeline('sentiment-analysis')
9
+ # For financial sentiment analysis you can use:
10
+ # pipe = pipeline("text-classification", model="ProsusAI/finbert")
11
+
12
+ # Define function
13
+ def analyze_sentiment(text):
14
+ if text.strip() == "":
15
+ return {"error": "Please enter some text."}
16
+ result = pipe(text)
17
+ return result
18
+
19
+ # Gradio Interface
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("## Sentiment Analysis with Transformers")
22
+
23
+ with gr.Row():
24
+ text_input = gr.Textbox(
25
+ label="Enter your input:",
26
+ placeholder="Type text here...",
27
+ lines=4
28
+ )
29
+
30
+ output = gr.JSON(label="Output")
31
+
32
+ analyze_button = gr.Button("Analyze Sentiment")
33
+
34
+ analyze_button.click(
35
+ fn=analyze_sentiment,
36
+ inputs=text_input,
37
+ outputs=output
38
+ )
39
+
40
+ # Launch app
41
+ if __name__ == "__main__":
42
+ demo.launch()