Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +14 -14
src/streamlit_app.py
CHANGED
|
@@ -3,37 +3,37 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
| 3 |
import torch
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
st.set_page_config(page_title="
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
st.title("📊 Analyse de Sentiment - Modèle Fusionné")
|
| 9 |
-
st.write("Application d'analyse de sentiment optimisée avec RoBERTa (Merged Model).")
|
| 10 |
|
| 11 |
-
# Chargement direct et simple (vu que le modèle est fusionné avec son tokenizer)
|
| 12 |
@st.cache_resource
|
| 13 |
def load_model():
|
| 14 |
-
|
| 15 |
model_id = "Diary14/roberta-sentiment-lora"
|
| 16 |
|
| 17 |
-
|
| 18 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 19 |
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 20 |
return tokenizer, model
|
| 21 |
|
| 22 |
-
with st.spinner("
|
| 23 |
tokenizer, model = load_model()
|
| 24 |
|
| 25 |
-
|
| 26 |
user_input = st.text_area(
|
| 27 |
-
"
|
| 28 |
-
placeholder="
|
| 29 |
height=200
|
| 30 |
)
|
| 31 |
|
| 32 |
-
if st.button("
|
| 33 |
lines = [line.strip() for line in user_input.split("\n") if line.strip() != ""]
|
| 34 |
|
| 35 |
if not lines:
|
| 36 |
-
st.warning("
|
| 37 |
else:
|
| 38 |
inputs = tokenizer(lines, return_tensors="pt", truncation=True, padding=True)
|
| 39 |
|
|
@@ -45,8 +45,8 @@ if st.button("Analyser les avis"):
|
|
| 45 |
|
| 46 |
results = []
|
| 47 |
for text, pred in zip(lines, predictions):
|
| 48 |
-
sentiment = "
|
| 49 |
-
results.append({"
|
| 50 |
|
| 51 |
df = pd.DataFrame(results)
|
| 52 |
st.dataframe(df, use_container_width=True)
|
|
|
|
| 3 |
import torch
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="Sentiment Analysis", layout="wide")
|
| 7 |
+
|
| 8 |
+
st.title("Welcome to the Sentiment Analyzer")
|
| 9 |
+
st.write("**Note**: All reviews must be entered in English.")
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
|
|
|
| 12 |
@st.cache_resource
|
| 13 |
def load_model():
|
| 14 |
+
|
| 15 |
model_id = "Diary14/roberta-sentiment-lora"
|
| 16 |
|
| 17 |
+
|
| 18 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 19 |
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 20 |
return tokenizer, model
|
| 21 |
|
| 22 |
+
with st.spinner("Loading model"):
|
| 23 |
tokenizer, model = load_model()
|
| 24 |
|
| 25 |
+
|
| 26 |
user_input = st.text_area(
|
| 27 |
+
"Enter reviews here :",
|
| 28 |
+
placeholder="Example :\nThis product is amazing!\nI really don't like it....",
|
| 29 |
height=200
|
| 30 |
)
|
| 31 |
|
| 32 |
+
if st.button("Analyze reviews"):
|
| 33 |
lines = [line.strip() for line in user_input.split("\n") if line.strip() != ""]
|
| 34 |
|
| 35 |
if not lines:
|
| 36 |
+
st.warning("Please enter at least one review.")
|
| 37 |
else:
|
| 38 |
inputs = tokenizer(lines, return_tensors="pt", truncation=True, padding=True)
|
| 39 |
|
|
|
|
| 45 |
|
| 46 |
results = []
|
| 47 |
for text, pred in zip(lines, predictions):
|
| 48 |
+
sentiment = "Positive review" if pred == 1 else "Negative review"
|
| 49 |
+
results.append({"Text/Review": text, "Sentiment": sentiment})
|
| 50 |
|
| 51 |
df = pd.DataFrame(results)
|
| 52 |
st.dataframe(df, use_container_width=True)
|