Spaces:
Runtime error
Runtime error
Commenti app.py
Browse files
app.py
CHANGED
|
@@ -4,21 +4,16 @@ from src.dataset import LoadDataset
|
|
| 4 |
from sklearn.metrics import accuracy_score
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
#dataset = LoadDataset()
|
| 9 |
model = None
|
| 10 |
dataset = None
|
| 11 |
-
|
| 12 |
X = None
|
| 13 |
y = None
|
| 14 |
-
|
| 15 |
-
#y = dataset.y
|
| 16 |
-
# y_pred = model.predict(X)
|
| 17 |
-
y_pred = ['negative', 'neutral', 'positive','negative', 'neutral', 'positive','negative', 'neutral', 'positive','positive']
|
| 18 |
-
|
| 19 |
valori = ['negative', 'neutral', 'positive']
|
| 20 |
|
| 21 |
def predict_tweet(tweet,esito_atteso) :
|
|
|
|
| 22 |
X.append(tweet)
|
| 23 |
y.append(esito_atteso)
|
| 24 |
y_new = model.predict(tweet)[0]
|
|
@@ -26,15 +21,17 @@ def predict_tweet(tweet,esito_atteso) :
|
|
| 26 |
acc_new = f"{accuracy_score(y, y_pred)}"
|
| 27 |
return y_new,acc_new
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
if __name__ == "__main__":
|
| 32 |
-
|
| 33 |
model = Modello()
|
| 34 |
dataset = LoadDataset()
|
| 35 |
X = dataset.X
|
| 36 |
y = dataset.y
|
|
|
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
demo = gr.Interface(
|
| 39 |
fn=predict_tweet,
|
| 40 |
inputs=[gr.Textbox(label="Tweet"),gr.Dropdown(choices=valori,label="Esito atteso")],
|
|
@@ -42,5 +39,5 @@ if __name__ == "__main__":
|
|
| 42 |
flagging_mode = 'never'
|
| 43 |
)
|
| 44 |
|
| 45 |
-
|
| 46 |
demo.launch()
|
|
|
|
| 4 |
from sklearn.metrics import accuracy_score
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
# Dichiaro le variabili e costanti che mi serviranno in seguito
|
|
|
|
| 8 |
model = None
|
| 9 |
dataset = None
|
|
|
|
| 10 |
X = None
|
| 11 |
y = None
|
| 12 |
+
y_pred = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
valori = ['negative', 'neutral', 'positive']
|
| 14 |
|
| 15 |
def predict_tweet(tweet,esito_atteso) :
|
| 16 |
+
# Aggiunge gli input (tweet ed esito_atteso) e l'esito predetto al dataset; restituisce l'esito predetto e la nuova accuracy calcolata sul dataset aggiornato
|
| 17 |
X.append(tweet)
|
| 18 |
y.append(esito_atteso)
|
| 19 |
y_new = model.predict(tweet)[0]
|
|
|
|
| 21 |
acc_new = f"{accuracy_score(y, y_pred)}"
|
| 22 |
return y_new,acc_new
|
| 23 |
|
|
|
|
|
|
|
| 24 |
if __name__ == "__main__":
|
| 25 |
+
# Inizializza gli oggetti
|
| 26 |
model = Modello()
|
| 27 |
dataset = LoadDataset()
|
| 28 |
X = dataset.X
|
| 29 |
y = dataset.y
|
| 30 |
+
y_pred = model.predict(X)
|
| 31 |
|
| 32 |
+
# Definisce l'interfaccia grafica di Gradio
|
| 33 |
+
# Prende in input un testo (tweet) e il sentiment predetto (quest'ultimo scelto da un menu a tendina)
|
| 34 |
+
# Restituisce l'esito predetto e la nuova accuracy calcolata sul dataset aggiornato
|
| 35 |
demo = gr.Interface(
|
| 36 |
fn=predict_tweet,
|
| 37 |
inputs=[gr.Textbox(label="Tweet"),gr.Dropdown(choices=valori,label="Esito atteso")],
|
|
|
|
| 39 |
flagging_mode = 'never'
|
| 40 |
)
|
| 41 |
|
| 42 |
+
# Lancia l'interfaccia grafica
|
| 43 |
demo.launch()
|