peace4ever commited on
Commit
9799278
·
verified ·
1 Parent(s): 4d25ecb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -86
app.py CHANGED
@@ -1,86 +1,87 @@
1
- # import streamlit as st
2
-
3
- # from transformers import pipeline
4
-
5
- # model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
6
- # pipeline = pipeline(task="sentiment-analysis", model=model_name) # Load pre-trained pipeline
7
-
8
- # st.title("Эерэг? Сөрөг эсвэл аль нь ч биш?")
9
- # text = st.text_area("Өгүүлбэр оруулна уу?")
10
-
11
- # if text is not None:
12
- # predictions = pipeline(text)
13
- # label = predictions[0]["label"]
14
- # probability = predictions[0]["score"]
15
- # col1, col2 = st.columns(2)
16
- # col1.header("Sentiment")
17
- # col2.header("Probability")
18
-
19
- # if label == "entailment":
20
- # sentiment = "Negative"
21
- # elif label == "contradiction":
22
- # sentiment = "Neutral"
23
- # elif label == "neutral":
24
- # sentiment = "Positive"
25
-
26
- # col1.write(sentiment)
27
- # col2.write(f"{probability:.2f}")
28
-
29
- from transformers import pipeline
30
- from tkinter import *
31
-
32
- # Load pre-trained sentiment analysis pipeline (replace with your actual model name)
33
- model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
34
- pipeline = pipeline(task="sentiment-analysis", model=model_name)
35
-
36
- def analyze_sentiment(text):
37
- """
38
- This function takes user input, performs sentiment analysis using your fine-tuned model,
39
- maps the predicted labels to desired sentiment categories, and returns the sentiment.
40
- """
41
- predictions = pipeline(text)
42
- label = predictions[0]["label"]
43
- probability = predictions[0]["score"]
44
-
45
- sentiment_map = {
46
- "entailment": "Negative", # Map based on your fine-tuned model's labels
47
- "contradiction": "Neutral",
48
- "neutral": "Positive",
49
- # Add more mappings if needed
50
- }
51
-
52
- sentiment = sentiment_map.get(label.upper(), "Unknown")
53
- return sentiment
54
-
55
- def main():
56
- """
57
- This function creates the main window and handles user interaction.
58
- """
59
- window = Tk()
60
- window.title("Эерэг? Сөрөг эсвэл аль нь ч биш?")
61
-
62
- # Text box for user input
63
- text_box = Text(window)
64
- text_box.pack(padx=10, pady=10)
65
-
66
- # Button to trigger sentiment analysis
67
- analyze_button = Button(window, text="Анализ хийх", command=lambda: update_sentiment(text_box.get("1.0", END)))
68
- analyze_button.pack(pady=10)
69
-
70
- # Label to display sentiment result
71
- sentiment_label = Label(window, text="")
72
- sentiment_label.pack()
73
-
74
- def update_sentiment(text):
75
- """
76
- This function performs sentiment analysis and updates the sentiment label.
77
- """
78
- sentiment = analyze_sentiment(text)
79
- sentiment_label.config(text=f"Sentiment: {sentiment}")
80
-
81
- window.mainloop()
82
-
83
- if __name__ == "__main__":
84
- main()
85
-
86
-
 
 
1
+ # import streamlit as st
2
+
3
+ # from transformers import pipeline
4
+
5
+ # model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
6
+ # pipeline = pipeline(task="sentiment-analysis", model=model_name) # Load pre-trained pipeline
7
+
8
+ # st.title("Эерэг? Сөрөг эсвэл аль нь ч биш?")
9
+ # text = st.text_area("Өгүүлбэр оруулна уу?")
10
+
11
+ # if text is not None:
12
+ # predictions = pipeline(text)
13
+ # label = predictions[0]["label"]
14
+ # probability = predictions[0]["score"]
15
+ # col1, col2 = st.columns(2)
16
+ # col1.header("Sentiment")
17
+ # col2.header("Probability")
18
+
19
+ # if label == "entailment":
20
+ # sentiment = "Negative"
21
+ # elif label == "contradiction":
22
+ # sentiment = "Neutral"
23
+ # elif label == "neutral":
24
+ # sentiment = "Positive"
25
+
26
+ # col1.write(sentiment)
27
+ # col2.write(f"{probability:.2f}")
28
+
29
+ from transformers import pipeline
30
+ from tkinter import *
31
+
32
+ # Load pre-trained sentiment analysis pipeline (replace with your actual model name)
33
+ model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
34
+ pipeline = pipeline(task="sentiment-analysis", model=model_name)
35
+
36
+ def analyze_sentiment(text):
37
+ """
38
+ This function takes user input, performs sentiment analysis using your fine-tuned model,
39
+ maps the predicted labels to desired sentiment categories, and returns the sentiment.
40
+ """
41
+ predictions = pipeline(text)
42
+ label = predictions[0]["label"]
43
+ probability = predictions[0]["score"]
44
+
45
+ sentiment_map = {
46
+ "entailment": "Negative", # Map based on your fine-tuned model's labels
47
+ "contradiction": "Neutral",
48
+ "neutral": "Positive",
49
+ # Add more mappings if needed
50
+ }
51
+
52
+ sentiment = sentiment_map.get(label.upper(), "Unknown")
53
+ return sentiment
54
+
55
+ def main():
56
+ """
57
+ This function creates the main window and handles user interaction.
58
+ """
59
+ window = Tk()
60
+ window.title("Эерэг? Сөрөг эсвэл аль нь ч биш?")
61
+
62
+ # Text box for user input
63
+ text_box = Text(window)
64
+ text_box.pack(padx=10, pady=10)
65
+
66
+ # Button to trigger sentiment analysis
67
+ analyze_button = Button(window, text="Анализ хийх", command=lambda: update_sentiment(text_box.get("1.0", END)))
68
+ analyze_button.pack(pady=10)
69
+
70
+ # Label to display sentiment result
71
+ sentiment_label = Label(window, text="")
72
+ sentiment_label.pack()
73
+
74
+ def update_sentiment(text):
75
+ """
76
+ This function performs sentiment analysis and updates the sentiment label.
77
+ """
78
+ sentiment = analyze_sentiment(text)
79
+ sentiment_label.config(text=f"Sentiment: {sentiment}")
80
+
81
+ window.mainloop()
82
+
83
+ if __name__ == "__main__":
84
+ app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
85
+
86
+
87
+