Roboproch commited on
Commit
ef2614f
·
1 Parent(s): 422d5d0

modifiche app.py e modello.py

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -4
  2. app.py +19 -2
  3. src/modello.py +5 -3
Dockerfile CHANGED
@@ -1,9 +1,9 @@
1
  #dockerfile
2
 
3
- # versione di Python
4
  FROM python:3.12.1
5
 
6
- # set della working directory
7
  WORKDIR /app
8
  RUN ls
9
 
@@ -13,8 +13,8 @@ COPY requirements.txt .
13
  # Installa le dipendenze
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
- # copia della directory in /app
17
  COPY . /app
18
 
19
- # run dello script Python
20
  CMD ["python", "app.py"]
 
1
  #dockerfile
2
 
3
+ # Versione di Python
4
  FROM python:3.12.1
5
 
6
+ # Set della working directory
7
  WORKDIR /app
8
  RUN ls
9
 
 
13
  # Installa le dipendenze
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
+ # Copia della directory in /app
17
  COPY . /app
18
 
19
+ # Run dello script Python
20
  CMD ["python", "app.py"]
app.py CHANGED
@@ -1,6 +1,23 @@
1
- print("TESTTTTT")
2
  # Utilities
3
  from src.modello import Modello
4
  from src.dataset import LoadDataset
 
5
 
6
- print("Hello TEST")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Utilities
2
  from src.modello import Modello
3
  from src.dataset import LoadDataset
4
+ from sklearn.metrics import accuracy_score
5
 
6
+ model = Modello()
7
+ dataset = LoadDataset()
8
+
9
+ # Considero solo una parte del dataset per motivi prestazionali
10
+ X = dataset.X[:200].tolist()
11
+ y = dataset.y[:200].tolist()
12
+
13
+ y_pred=model.predict(X)
14
+
15
+ check_loop = True
16
+
17
+ while check_loop :
18
+ tweet = input("Inserire tweet:")
19
+ if tweet=="" :
20
+ print("EXIT")
21
+ check_loop = False
22
+ else :
23
+ print(f"Sentiment: {model.predict(tweet)}")
src/modello.py CHANGED
@@ -5,6 +5,8 @@ class Modello :
5
  # Import del modello da Hugging Face
6
  sentiment_task = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment-latest", tokenizer="cardiffnlp/twitter-roberta-base-sentiment-latest")
7
 
8
- def predict(self,tweet) :
9
- # Metodo per le predizioni
10
- return self.sentiment_task(tweet)[0]["label"]
 
 
 
5
  # Import del modello da Hugging Face
6
  sentiment_task = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment-latest", tokenizer="cardiffnlp/twitter-roberta-base-sentiment-latest")
7
 
8
+ def predict(self,tweets) :
9
+ # Metodo per le predizioni, prende in input una o più stringhe
10
+ # Definisco un batch_size per efficienza
11
+ results = self.sentiment_task(tweets, batch_size=32)
12
+ return [res["label"] for res in results]