Spaces:
Runtime error
Runtime error
fix pro efficientamento
Browse files- app.py +23 -11
- src/dataset.py +13 -12
app.py
CHANGED
|
@@ -4,11 +4,15 @@ from src.dataset import LoadDataset
|
|
| 4 |
from sklearn.metrics import accuracy_score
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
-
model = Modello()
|
| 8 |
-
dataset = LoadDataset()
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
X =
|
| 11 |
-
y =
|
|
|
|
|
|
|
| 12 |
# y_pred = model.predict(X)
|
| 13 |
y_pred = ['negative', 'neutral', 'positive','negative', 'neutral', 'positive','negative', 'neutral', 'positive','positive']
|
| 14 |
|
|
@@ -22,13 +26,21 @@ def predict_tweet(tweet,esito_atteso) :
|
|
| 22 |
acc_new = f"{accuracy_score(y, y_pred)}"
|
| 23 |
return y_new,acc_new
|
| 24 |
|
| 25 |
-
|
| 26 |
-
fn=predict_tweet,
|
| 27 |
-
inputs=[gr.Textbox(label="Tweet"),gr.Dropdown(choices=valori,label="Esito atteso")],
|
| 28 |
-
outputs=[gr.Textbox(label="Previsione modello"),gr.Textbox(label="Ricalcolo accuracy")],
|
| 29 |
-
flagging_mode = 'never'
|
| 30 |
-
)
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
demo.launch()
|
|
|
|
| 4 |
from sklearn.metrics import accuracy_score
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
#model = Modello()
|
| 8 |
+
#dataset = LoadDataset()
|
| 9 |
+
model = None
|
| 10 |
+
dataset = None
|
| 11 |
|
| 12 |
+
X = None
|
| 13 |
+
y = None
|
| 14 |
+
#X = dataset.X
|
| 15 |
+
#y = dataset.y
|
| 16 |
# y_pred = model.predict(X)
|
| 17 |
y_pred = ['negative', 'neutral', 'positive','negative', 'neutral', 'positive','negative', 'neutral', 'positive','positive']
|
| 18 |
|
|
|
|
| 26 |
acc_new = f"{accuracy_score(y, y_pred)}"
|
| 27 |
return y_new,acc_new
|
| 28 |
|
| 29 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
+
print("Avvio caricamento componenti...")
|
| 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")],
|
| 41 |
+
outputs=[gr.Textbox(label="Previsione modello"),gr.Textbox(label="Ricalcolo accuracy")],
|
| 42 |
+
flagging_mode = 'never'
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
print("Lancio")
|
| 46 |
demo.launch()
|
src/dataset.py
CHANGED
|
@@ -6,18 +6,19 @@ class LoadDataset :
|
|
| 6 |
Classe utilizzata per scaricare il dataset e rendere disponibili set di train e set di test
|
| 7 |
"""
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 6 |
Classe utilizzata per scaricare il dataset e rendere disponibili set di train e set di test
|
| 7 |
"""
|
| 8 |
|
| 9 |
+
def __init__(self) :
|
| 10 |
+
# Import del dataset da Hugging Face
|
| 11 |
+
# Prendo solo 200 record per problemi di timeout in fase di caricamento su HuggingFace di un dataset troppo grosso
|
| 12 |
+
self.ds = load_dataset("SetFit/tweet_sentiment_extraction", split="train", streaming=True).take(10)
|
| 13 |
|
| 14 |
+
# Per comodità trasformo il dataset in un dataframe di pandas
|
| 15 |
+
# df = ds.to_pandas()
|
| 16 |
+
self.df = pd.DataFrame(list(self.ds))
|
| 17 |
|
| 18 |
+
# Identifico feature e target
|
| 19 |
+
self.X = self.df['text'].tolist()
|
| 20 |
+
self.y = self.df['label_text'].tolist()
|
| 21 |
|
| 22 |
+
# Considero solo una parte del dataset per motivi prestazionali
|
| 23 |
+
#X = X.tolist()
|
| 24 |
+
#y = y.tolist()
|