Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from datetime import datetime
|
|
9 |
|
10 |
from spacy.cli import download
|
11 |
|
|
|
12 |
try:
|
13 |
nlp = spacy.load("en_core_web_sm")
|
14 |
except OSError:
|
@@ -16,7 +17,7 @@ except OSError:
|
|
16 |
download("en_core_web_sm")
|
17 |
nlp = spacy.load("en_core_web_sm")
|
18 |
|
19 |
-
|
20 |
qg_model = AutoModelForSeq2SeqLM.from_pretrained("valhalla/t5-base-qa-qg-hl")
|
21 |
qg_tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-base-qa-qg-hl", use_fast=True)
|
22 |
qg_pipeline = pipeline("text2text-generation", model=qg_model, tokenizer=qg_tokenizer)
|
@@ -82,11 +83,16 @@ def save_json_to_dataset(json_str):
|
|
82 |
if not hf_token:
|
83 |
return "β HF_TOKEN not found in environment."
|
84 |
|
85 |
-
repo_id = "University_Inquiries_AI_Chatbot"
|
86 |
dataset_file = "dataset.json"
|
87 |
local_dir = "hf_repo"
|
88 |
|
89 |
-
repo = Repository(
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
repo.git_pull()
|
92 |
|
@@ -102,8 +108,8 @@ def save_json_to_dataset(json_str):
|
|
102 |
|
103 |
now = datetime.now()
|
104 |
for entry in new_data:
|
105 |
-
entry["month"] = now.strftime("%B")
|
106 |
-
entry["year"] = now.year
|
107 |
|
108 |
updated_data = existing_data + new_data
|
109 |
|
@@ -116,7 +122,6 @@ def save_json_to_dataset(json_str):
|
|
116 |
except Exception as e:
|
117 |
return f"β Error: {str(e)}"
|
118 |
|
119 |
-
|
120 |
def on_extract_facts(text):
|
121 |
facts = extract_paragraph_facts(text)
|
122 |
default_fact = facts[0] if facts else None
|
@@ -163,7 +168,6 @@ def main():
|
|
163 |
placeholder='{\n"question": "Your question?",\n"answer": "Your answer."\n},'
|
164 |
)
|
165 |
|
166 |
-
|
167 |
with gr.Row():
|
168 |
generate_btn = gr.Button("Generate Q&A")
|
169 |
send_btn = gr.Button("π€ Send to Dataset")
|
|
|
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 |
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)
|
|
|
83 |
if not hf_token:
|
84 |
return "β HF_TOKEN not found in environment."
|
85 |
|
86 |
+
repo_id = "UniversityAIChatbot/University_Inquiries_AI_Chatbot"
|
87 |
dataset_file = "dataset.json"
|
88 |
local_dir = "hf_repo"
|
89 |
|
90 |
+
repo = Repository(
|
91 |
+
local_dir=local_dir,
|
92 |
+
clone_from=f"datasets/{repo_id}",
|
93 |
+
use_auth_token=hf_token,
|
94 |
+
repo_type="dataset"
|
95 |
+
)
|
96 |
|
97 |
repo.git_pull()
|
98 |
|
|
|
108 |
|
109 |
now = datetime.now()
|
110 |
for entry in new_data:
|
111 |
+
entry["month"] = now.strftime("%B")
|
112 |
+
entry["year"] = now.year
|
113 |
|
114 |
updated_data = existing_data + new_data
|
115 |
|
|
|
122 |
except Exception as e:
|
123 |
return f"β Error: {str(e)}"
|
124 |
|
|
|
125 |
def on_extract_facts(text):
|
126 |
facts = extract_paragraph_facts(text)
|
127 |
default_fact = facts[0] if facts else None
|
|
|
168 |
placeholder='{\n"question": "Your question?",\n"answer": "Your answer."\n},'
|
169 |
)
|
170 |
|
|
|
171 |
with gr.Row():
|
172 |
generate_btn = gr.Button("Generate Q&A")
|
173 |
send_btn = gr.Button("π€ Send to Dataset")
|