Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
-
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 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 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# Launch the Gradio app
|
| 21 |
if __name__ == "__main__":
|
| 22 |
-
|
|
|
|
| 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)
|