Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ from datetime import datetime
|
|
9 |
|
10 |
from spacy.cli import download
|
11 |
|
12 |
-
# Load or download the spaCy model
|
13 |
try:
|
14 |
nlp = spacy.load("en_core_web_sm")
|
15 |
except OSError:
|
@@ -17,7 +16,6 @@ except OSError:
|
|
17 |
download("en_core_web_sm")
|
18 |
nlp = spacy.load("en_core_web_sm")
|
19 |
|
20 |
-
# Load question generation model
|
21 |
qg_model = AutoModelForSeq2SeqLM.from_pretrained("valhalla/t5-base-qa-qg-hl")
|
22 |
qg_tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-base-qa-qg-hl", use_fast=True)
|
23 |
qg_pipeline = pipeline("text2text-generation", model=qg_model, tokenizer=qg_tokenizer)
|
@@ -84,20 +82,18 @@ def save_json_to_dataset(json_str):
|
|
84 |
return "β HF_TOKEN not found in environment."
|
85 |
|
86 |
repo_id = "UniversityAIChatbot/University_Inquiries_AI_Chatbot"
|
87 |
-
|
88 |
local_dir = "hf_repo"
|
89 |
|
90 |
-
# β
Corrected clone_from
|
91 |
repo = Repository(
|
92 |
local_dir=local_dir,
|
93 |
-
clone_from=repo_id,
|
94 |
use_auth_token=hf_token,
|
95 |
-
repo_type="dataset"
|
96 |
)
|
97 |
|
98 |
repo.git_pull()
|
99 |
|
100 |
-
full_path = os.path.join(local_dir,
|
101 |
|
102 |
if os.path.exists(full_path):
|
103 |
with open(full_path, "r", encoding="utf-8") as f:
|
@@ -117,9 +113,9 @@ def save_json_to_dataset(json_str):
|
|
117 |
with open(full_path, "w", encoding="utf-8") as f:
|
118 |
json.dump(updated_data, f, indent=2, ensure_ascii=False)
|
119 |
|
120 |
-
repo.push_to_hub(commit_message="π₯ Add new Q&A
|
121 |
|
122 |
-
return "β
Data with timestamp successfully pushed to
|
123 |
except Exception as e:
|
124 |
return f"β Error: {str(e)}"
|
125 |
|
|
|
9 |
|
10 |
from spacy.cli import download
|
11 |
|
|
|
12 |
try:
|
13 |
nlp = spacy.load("en_core_web_sm")
|
14 |
except OSError:
|
|
|
16 |
download("en_core_web_sm")
|
17 |
nlp = spacy.load("en_core_web_sm")
|
18 |
|
|
|
19 |
qg_model = AutoModelForSeq2SeqLM.from_pretrained("valhalla/t5-base-qa-qg-hl")
|
20 |
qg_tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-base-qa-qg-hl", use_fast=True)
|
21 |
qg_pipeline = pipeline("text2text-generation", model=qg_model, tokenizer=qg_tokenizer)
|
|
|
82 |
return "β HF_TOKEN not found in environment."
|
83 |
|
84 |
repo_id = "UniversityAIChatbot/University_Inquiries_AI_Chatbot"
|
85 |
+
target_file = "database.json"
|
86 |
local_dir = "hf_repo"
|
87 |
|
|
|
88 |
repo = Repository(
|
89 |
local_dir=local_dir,
|
90 |
+
clone_from=repo_id,
|
91 |
use_auth_token=hf_token,
|
|
|
92 |
)
|
93 |
|
94 |
repo.git_pull()
|
95 |
|
96 |
+
full_path = os.path.join(local_dir, target_file)
|
97 |
|
98 |
if os.path.exists(full_path):
|
99 |
with open(full_path, "r", encoding="utf-8") as f:
|
|
|
113 |
with open(full_path, "w", encoding="utf-8") as f:
|
114 |
json.dump(updated_data, f, indent=2, ensure_ascii=False)
|
115 |
|
116 |
+
repo.push_to_hub(commit_message="π₯ Add new Q&A to database.json")
|
117 |
|
118 |
+
return "β
Data with timestamp successfully pushed to Space!"
|
119 |
except Exception as e:
|
120 |
return f"β Error: {str(e)}"
|
121 |
|