Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,20 +5,26 @@ import builtins
|
|
| 5 |
import os
|
| 6 |
import json
|
| 7 |
|
| 8 |
-
DATA_FILE = "
|
| 9 |
|
| 10 |
def load_data():
|
| 11 |
"""Carica i dati salvati (token e frasi) dal file JSON."""
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
return {"tokens": [], "phrases": {}}
|
| 16 |
|
| 17 |
def save_data(data):
|
| 18 |
"""Salva i dati (token e frasi) nel file JSON."""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
json.dump(data, f, indent=4)
|
| 21 |
|
|
|
|
| 22 |
data = load_data()
|
| 23 |
|
| 24 |
def save_token_and_phrase(token, phrase):
|
|
@@ -75,7 +81,7 @@ for i, example in enumerate(examples, start=1):
|
|
| 75 |
|
| 76 |
# UI per l'inserimento del token e delle frasi
|
| 77 |
st.sidebar.header("Gestione Token e Frasi")
|
| 78 |
-
token_input = st.sidebar.text_input("
|
| 79 |
if st.sidebar.button("Salva Token e Frase"):
|
| 80 |
if token_input:
|
| 81 |
save_token_and_phrase(token_input, st.session_state.get("input_text_value"))
|
|
|
|
| 5 |
import os
|
| 6 |
import json
|
| 7 |
|
| 8 |
+
DATA_FILE = "data.json"
|
| 9 |
|
| 10 |
def load_data():
|
| 11 |
"""Carica i dati salvati (token e frasi) dal file JSON."""
|
| 12 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
file_path = os.path.join(script_dir, DATA_FILE)
|
| 14 |
+
|
| 15 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 16 |
+
return json.load(f)
|
| 17 |
return {"tokens": [], "phrases": {}}
|
| 18 |
|
| 19 |
def save_data(data):
|
| 20 |
"""Salva i dati (token e frasi) nel file JSON."""
|
| 21 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
+
file_path = os.path.join(script_dir, DATA_FILE)
|
| 23 |
+
|
| 24 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 25 |
json.dump(data, f, indent=4)
|
| 26 |
|
| 27 |
+
|
| 28 |
data = load_data()
|
| 29 |
|
| 30 |
def save_token_and_phrase(token, phrase):
|
|
|
|
| 81 |
|
| 82 |
# UI per l'inserimento del token e delle frasi
|
| 83 |
st.sidebar.header("Gestione Token e Frasi")
|
| 84 |
+
token_input = st.sidebar.text_input("Se la predizione è errata, salva il token corretto:")
|
| 85 |
if st.sidebar.button("Salva Token e Frase"):
|
| 86 |
if token_input:
|
| 87 |
save_token_and_phrase(token_input, st.session_state.get("input_text_value"))
|