Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,16 +4,34 @@ from cltk.data.fetch import FetchCorpus
|
|
4 |
import builtins
|
5 |
import os
|
6 |
import json
|
|
|
7 |
|
|
|
|
|
|
|
8 |
DATA_FILE = "data.json"
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return {"tokens": [], "phrases": {}}
|
18 |
|
19 |
def save_data(data):
|
@@ -85,6 +103,7 @@ token_input = st.sidebar.text_input("Se la predizione è errata, salva il token
|
|
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"))
|
|
|
88 |
st.sidebar.success("Token e frase salvati con successo!")
|
89 |
else:
|
90 |
st.sidebar.warning("Inserisci sia un token che una frase validi.")
|
|
|
4 |
import builtins
|
5 |
import os
|
6 |
import json
|
7 |
+
from git import Repo
|
8 |
|
9 |
+
GITHUB_RAW_URL = "https://raw.githubusercontent.com/Cicciokr/latin-ai-model/main/data.json"
|
10 |
+
GITHUB_REPO = "https://github.com/Cicciokr/latin-ai-model"
|
11 |
+
GITHUB_TOKEN = "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"
|
12 |
DATA_FILE = "data.json"
|
13 |
|
14 |
+
def upload_to_github():
|
15 |
+
repo_dir = "./"
|
16 |
+
if not os.path.exists(repo_dir):
|
17 |
+
Repo.clone_from(GITHUB_REPO.replace("https://", f"https://{GITHUB_TOKEN}@"), repo_dir)
|
18 |
+
repo = Repo(repo_dir)
|
19 |
+
file_path = os.path.join(repo_dir, "data.json")
|
20 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
21 |
+
json.dump(data, f, indent=4)
|
22 |
+
repo.git.add("data.json")
|
23 |
+
repo.index.commit("Aggiornato data.json")
|
24 |
+
repo.remote().push()
|
25 |
+
st.sidebar.success("File JSON aggiornato su GitHub!")
|
26 |
|
27 |
+
def load_data():
|
28 |
+
"""Carica i dati salvati (token e frasi) dal file JSON da GitHub."""
|
29 |
+
try:
|
30 |
+
response = requests.get(GITHUB_RAW_URL)
|
31 |
+
if response.status_code == 200:
|
32 |
+
return response.json()
|
33 |
+
except requests.exceptions.RequestException:
|
34 |
+
pass
|
35 |
return {"tokens": [], "phrases": {}}
|
36 |
|
37 |
def save_data(data):
|
|
|
103 |
if st.sidebar.button("Salva Token e Frase"):
|
104 |
if token_input:
|
105 |
save_token_and_phrase(token_input, st.session_state.get("input_text_value"))
|
106 |
+
upload_to_github()
|
107 |
st.sidebar.success("Token e frase salvati con successo!")
|
108 |
else:
|
109 |
st.sidebar.warning("Inserisci sia un token che una frase validi.")
|