peace4ever commited on
Commit
8a0fb54
1 Parent(s): a0ce698

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -27
app.py CHANGED
@@ -1,9 +1,5 @@
1
- from flask import Flask, request, jsonify
2
  from transformers import pipeline
3
- import os
4
-
5
- # Initialize Flask app
6
- app = Flask(__name__)
7
 
8
  # Load pre-trained sentiment analysis pipeline
9
  model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
@@ -22,28 +18,23 @@ def analyze_sentiment(text):
22
  "entailment": "Negative", # Map based on your fine-tuned model's labels
23
  "contradiction": "Neutral",
24
  "neutral": "Positive",
25
- # Add more mappings if needed
26
  }
27
 
28
- sentiment = sentiment_map.get(label.lower(), "Unknown")
29
- return {"sentiment": sentiment, "label": label, "probability": probability}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- @app.route('/analyze', methods=['POST'])
32
- def analyze():
33
- """
34
- This endpoint receives text data and returns the sentiment analysis result.
35
- """
36
- data = request.json
37
- if 'text' not in data:
38
- return jsonify({"error": "No text provided"}), 400
39
- text = data['text']
40
- result = analyze_sentiment(text)
41
- return jsonify(result)
42
-
43
- @app.route('/')
44
- def home():
45
- return "Welcome to the Sentiment Analysis API!"
46
-
47
- if __name__ == "__main__":
48
- port = int(os.environ.get("PORT", 7860))
49
- app.run(host="0.0.0.0", port=port)
 
1
+ import streamlit as st
2
  from transformers import pipeline
 
 
 
 
3
 
4
  # Load pre-trained sentiment analysis pipeline
5
  model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
 
18
  "entailment": "Negative", # Map based on your fine-tuned model's labels
19
  "contradiction": "Neutral",
20
  "neutral": "Positive",
 
21
  }
22
 
23
+ sentiment = sentiment_map.get(label.lower(), "Unknown")
24
+ return sentiment, label, probability
25
+
26
+ # Streamlit app layout
27
+ st.title("Mongolian Sentiment Analysis")
28
+ st.write("Enter some text to analyze its sentiment.")
29
+
30
+ user_input = st.text_area("Text input")
31
+
32
+ if st.button("Analyze"):
33
+ if user_input:
34
+ sentiment, label, probability = analyze_sentiment(user_input)
35
+ st.write(f"**Sentiment:** {sentiment}")
36
+ st.write(f"**Label:** {label}")
37
+ st.write(f"**Probability:** {probability:.2f}")
38
+ else:
39
+ st.write("Please enter some text to analyze.")
40