Spaces:
Paused
Paused
Davide Fiocco commited on
Commit ·
dcf6f0c
1
Parent(s): 0f77545
Allow year to update automatically
Browse files- app.py +4 -6
- context.json +1 -1
- utils.py +13 -0
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import tokenizers
|
|
| 5 |
import torch
|
| 6 |
from transformers import Pipeline, pipeline
|
| 7 |
|
| 8 |
-
from utils import get_answer
|
| 9 |
|
| 10 |
|
| 11 |
@st.cache(
|
|
@@ -34,8 +34,7 @@ with st.spinner(
|
|
| 34 |
|
| 35 |
engine = load_engine()
|
| 36 |
|
| 37 |
-
|
| 38 |
-
context = json.load(f)
|
| 39 |
|
| 40 |
st.title("Le risposte alle tue domande personali")
|
| 41 |
|
|
@@ -43,10 +42,9 @@ input = st.text_input("Scrivi una domanda in italiano e comparirà la risposta!"
|
|
| 43 |
|
| 44 |
if input:
|
| 45 |
try:
|
| 46 |
-
|
| 47 |
-
answer = get_answer(input, context
|
| 48 |
st.subheader(answer)
|
| 49 |
-
|
| 50 |
except:
|
| 51 |
|
| 52 |
st.error(
|
|
|
|
| 5 |
import torch
|
| 6 |
from transformers import Pipeline, pipeline
|
| 7 |
|
| 8 |
+
from utils import get_answer, get_context
|
| 9 |
|
| 10 |
|
| 11 |
@st.cache(
|
|
|
|
| 34 |
|
| 35 |
engine = load_engine()
|
| 36 |
|
| 37 |
+
|
|
|
|
| 38 |
|
| 39 |
st.title("Le risposte alle tue domande personali")
|
| 40 |
|
|
|
|
| 42 |
|
| 43 |
if input:
|
| 44 |
try:
|
| 45 |
+
context = get_context()
|
| 46 |
+
answer = get_answer(input, context, engine)
|
| 47 |
st.subheader(answer)
|
|
|
|
| 48 |
except:
|
| 49 |
|
| 50 |
st.error(
|
context.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
{"info": "Sei Giuseppe. Hai 69 anni. Sei nato nel 1952. Hai perso la memoria. Sei nato in Veneto. Abiti e vivi a Villafranca di Verona con Davide in Corso Vittorio Emanuele 238. Ora siamo
|
| 2 |
}
|
|
|
|
| 1 |
+
{"info": "Sei Giuseppe. Hai 69 anni. Sei nato nel 1952. Hai perso la memoria. Sei nato in Veneto. Abiti e vivi a Villafranca di Verona con Davide in Corso Vittorio Emanuele 238. Ora siamo nell'anno [YEAR] e hai avuto un'encefalite virale a gennaio 2021. Hai perso la memoria a causa dell'encefalite. Hai i capelli grigi. Pesi circa 85 kg, sei un po' ciccione. Sei alto 173 cm. Hai studiato Ingegneria elettronica a Padova, sei intelligente ma molto smemorato. Hai 10 dita delle mani e 10 dita dei piedi. Davide è tuo figlio, ha 37 anni. I medici dicono che stai migliorando lentamente. Tua moglie Raffaella abita a Verona. Raffaella sta bene. Sei separato da Raffaella da circa 10 anni. Con Raffaella hai rapporti cordiali. Alessandro, Giovanni e Grazia sono i tuoi fratelli. I tuoi fratelli stanno bene."
|
| 2 |
}
|
utils.py
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def get_answer(input, context, engine):
|
| 2 |
|
| 3 |
answer = engine({"question": input, "context": context})
|
| 4 |
|
| 5 |
return answer["answer"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import datetime
|
| 3 |
+
|
| 4 |
def get_answer(input, context, engine):
|
| 5 |
|
| 6 |
answer = engine({"question": input, "context": context})
|
| 7 |
|
| 8 |
return answer["answer"]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_context():
|
| 12 |
+
|
| 13 |
+
now = datetime.datetime.now()
|
| 14 |
+
|
| 15 |
+
with open("context.json") as f:
|
| 16 |
+
context = json.load(f)["info"].replace("[YEAR]", str(now.year))
|
| 17 |
+
|
| 18 |
+
return context
|