Diary14 commited on
Commit
b83203e
·
verified ·
1 Parent(s): fab084c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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="Analyse de Sentiment", page_icon="📊", layout="wide")
 
 
 
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
- # L'identifiant exact de ton dépôt sur Hugging Face
15
  model_id = "Diary14/roberta-sentiment-lora"
16
 
17
- # Hugging Face va trouver le tokenizer et le modèle dans le même dossier
18
  tokenizer = AutoTokenizer.from_pretrained(model_id)
19
  model = AutoModelForSequenceClassification.from_pretrained(model_id)
20
  return tokenizer, model
21
 
22
- with st.spinner("Chargement du modèle fusionné en cours..."):
23
  tokenizer, model = load_model()
24
 
25
- # Zone de saisie
26
  user_input = st.text_area(
27
- "Entrez vos avis (un avis par ligne) :",
28
- placeholder="Exemple :\nCe produit est top !\nJe n'aime pas du tout...",
29
  height=200
30
  )
31
 
32
- if st.button("Analyser les avis"):
33
  lines = [line.strip() for line in user_input.split("\n") if line.strip() != ""]
34
 
35
  if not lines:
36
- st.warning("Veuillez entrer au moins un texte.")
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 = "POSITIF " if pred == 1 else "NÉGATIF 🚨"
49
- results.append({"Texte/Avis": text, "Sentiment": sentiment})
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)