Swathi6 commited on
Commit
7685acc
·
verified ·
1 Parent(s): bd0804a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,22 +1,18 @@
 
1
  from transformers import pipeline
2
- import gradio as gr
3
 
4
- # Load Hugging Face sentiment analysis pipeline
5
- sentiment_pipeline = pipeline("sentiment-analysis")
6
 
7
- # Gradio interface function
8
- def analyze_sentiment(text):
9
- result = sentiment_pipeline(text)
10
- label = result[0]['label']
11
- score = result[0]['score']
12
- return f"Sentiment: {label} (Confidence: {score:.2f})"
13
 
14
- # Gradio App
15
- demo = gr.Interface(fn=analyze_sentiment,
16
- inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
17
- outputs="text",
18
- title="Sentiment Analyzer")
 
 
19
 
20
- # Launch the Gradio app
21
  if __name__ == "__main__":
22
- demo.launch()
 
1
+ from flask import Flask, render_template, request
2
  from transformers import pipeline
 
3
 
4
+ app = Flask(__name__)
 
5
 
6
+ # Load sentiment analysis pipeline
7
+ classifier = pipeline("sentiment-analysis")
 
 
 
 
8
 
9
+ @app.route("/", methods=["GET", "POST"])
10
+ def home():
11
+ result = None
12
+ if request.method == "POST":
13
+ user_input = request.form["user_input"]
14
+ result = classifier(user_input)[0] # result is a dict with 'label' and 'score'
15
+ return render_template("index.html", result=result)
16
 
 
17
  if __name__ == "__main__":
18
+ app.run(debug=True)