riccardomusmeci commited on
Commit
2e79952
·
verified ·
1 Parent(s): c335858

Upload space.py

Browse files
Files changed (1) hide show
  1. space.py +12 -2
space.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  from peft import PeftModel
5
  import json
 
6
 
7
  MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
8
  ADAPTER_REPO = "riccardomusmeci/SentimentProfAI"
@@ -26,7 +27,16 @@ model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
26
  model.to(device)
27
  model.eval()
28
 
29
- def sentiment_analysis(review_text):
 
 
 
 
 
 
 
 
 
30
  prompt = f"{SYSTEM_PROMPT}<|user|>\n{review_text}</s>\n<|assistant|>\n"
31
  inputs = tokenizer(prompt, return_tensors="pt").to(device)
32
  with torch.no_grad():
@@ -58,7 +68,7 @@ iface = gr.Interface(
58
  gr.Textbox(label="Reasoning")
59
  ],
60
  title="Sentiment Analysis ProfAI",
61
- description="Analizza la recensione di un film e restituisce il sentiment (positivo/negativo) e la motivazione."
62
  )
63
 
64
  if __name__ == "__main__":
 
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  from peft import PeftModel
5
  import json
6
+ from typing import Tuple
7
 
8
  MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
9
  ADAPTER_REPO = "riccardomusmeci/SentimentProfAI"
 
27
  model.to(device)
28
  model.eval()
29
 
30
+ def sentiment_analysis(review_text: str) -> Tuple[str, str]:
31
+ """Analyze the sentiment of a movie review and return the label and reasoning.
32
+
33
+ Args:
34
+ review_text (str): The movie review text to analyze.
35
+
36
+ Returns:
37
+ Tuple[str, str]: A tuple containing the sentiment label ("positive" or "negative") and the reasoning for the classification.
38
+
39
+ """
40
  prompt = f"{SYSTEM_PROMPT}<|user|>\n{review_text}</s>\n<|assistant|>\n"
41
  inputs = tokenizer(prompt, return_tensors="pt").to(device)
42
  with torch.no_grad():
 
68
  gr.Textbox(label="Reasoning")
69
  ],
70
  title="Sentiment Analysis ProfAI",
71
+ description="Analizza il testo e restituisce il sentiment (positivo/negativo) e la motivazione."
72
  )
73
 
74
  if __name__ == "__main__":