Spaces:
Runtime error
Runtime error
Peter Szemraj
commited on
Commit
•
c3b001a
1
Parent(s):
b9d3930
update app
Browse files
app.py
CHANGED
@@ -25,7 +25,6 @@ from grammar_improve import (
|
|
25 |
remove_trailing_punctuation,
|
26 |
build_symspell_obj,
|
27 |
symspeller,
|
28 |
-
fix_punct_spacing,
|
29 |
)
|
30 |
|
31 |
from utils import (
|
@@ -45,13 +44,10 @@ cwd = Path.cwd()
|
|
45 |
my_cwd = str(cwd.resolve()) # string so it can be passed to os.path() objects
|
46 |
|
47 |
|
48 |
-
def chat(trivia_query):
|
49 |
-
"""
|
50 |
-
chat - a function that takes in a trivia query and returns a response
|
51 |
|
52 |
-
|
53 |
history = []
|
54 |
-
response = ask_gpt(trivia_query, chat_pipe=my_chatbot
|
55 |
history = [trivia_query, response]
|
56 |
html = ""
|
57 |
for item in history:
|
@@ -93,7 +89,7 @@ def ask_gpt(
|
|
93 |
in_len = len(prompt)
|
94 |
if in_len > 512:
|
95 |
prompt = prompt[-512:] # truncate to 512 chars
|
96 |
-
print(f"Truncated prompt to last 512 chars: started with {in_len}
|
97 |
max_len = min(max_len, 512)
|
98 |
|
99 |
resp = discussion(
|
@@ -117,9 +113,8 @@ def ask_gpt(
|
|
117 |
else:
|
118 |
# no correction needed
|
119 |
cln_resp = rawtxt.strip()
|
120 |
-
|
121 |
-
|
122 |
-
print(f"the prompt was:\n\t{message}\nand the response was:\n\t{bot_resp}\n")
|
123 |
corr_rt = round(time.perf_counter() - gpt_et, 4)
|
124 |
print(
|
125 |
f"took {gpt_rt + corr_rt} sec to respond, {gpt_rt} for GPT, {corr_rt} for correction\n"
|
@@ -132,7 +127,7 @@ def get_parser():
|
|
132 |
get_parser - a helper function for the argparse module
|
133 |
"""
|
134 |
parser = argparse.ArgumentParser(
|
135 |
-
description="submit a question, GPT model responds"
|
136 |
)
|
137 |
parser.add_argument(
|
138 |
"-m",
|
@@ -186,7 +181,6 @@ if __name__ == "__main__":
|
|
186 |
chat,
|
187 |
inputs=["text"],
|
188 |
outputs="html",
|
189 |
-
examples_per_page=6,
|
190 |
examples=[
|
191 |
"How many people inhabit Rhode Island?",
|
192 |
"What do you call the wheeled contraption which carries an airplane's luggage from place to place?",
|
@@ -198,26 +192,14 @@ if __name__ == "__main__":
|
|
198 |
"Who was Charles de Gaulle?",
|
199 |
"Where is Stonehenge located?",
|
200 |
"How many moons does Saturn have?",
|
201 |
-
"How many people live in the United States?",
|
202 |
-
"What is the white house called?",
|
203 |
-
"Who was George Washington's father?",
|
204 |
-
"How many keys are there on a piano?",
|
205 |
-
"Who invented the telescope?",
|
206 |
-
"Who is your daddy and what does he do?",
|
207 |
-
"When did Christopher Columbus come to America?",
|
208 |
-
"What is the smallest thing in the world?",
|
209 |
-
"Why are there interstate highways that have only one lane on each side?",
|
210 |
-
"Who were Alexander Graham Bell's parents?",
|
211 |
-
"What is the name of the world's largest island?",
|
212 |
-
"Which flavor of ice cream is the most popular in Switzerland?",
|
213 |
],
|
214 |
title=f"Ballpark Trivia: {default_model} Model",
|
215 |
description=f"Are you frequently asked google-able Trivia questions and annoyed by it? Well, this is the app for you! Ballpark Trivia Bot answers any trivia question with something that sounds plausible but is probably not 100% correct. \n\n One might say.. the answers are in the right ballpark.",
|
216 |
-
article="Further details can be found in the [model card](https://huggingface.co/pszemraj/Ballpark-Trivia-XL)
|
217 |
"**Important Notes & About:**\n\n"
|
218 |
"1. the model can take up to 60 seconds to respond sometimes, patience is a virtue.\n"
|
219 |
"2. the model started from a pretrained checkpoint, and was trained on several different datasets. Anything it says should be fact-checked before being regarded as a true statement.\n"
|
220 |
-
"3. Some params are still being tweaked (in future, will have them as inputs) any feedback is welcome
|
221 |
css="""
|
222 |
.chatbox {display:flex;flex-direction:column}
|
223 |
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
@@ -226,12 +208,11 @@ if __name__ == "__main__":
|
|
226 |
""",
|
227 |
allow_screenshot=True,
|
228 |
allow_flagging="never",
|
229 |
-
theme="
|
230 |
)
|
231 |
|
232 |
# launch the gradio interface and start the server
|
233 |
iface.launch(
|
234 |
# prevent_thread_lock=True,
|
235 |
-
# share=True,
|
236 |
enable_queue=True, # also allows for dealing with multiple users simultaneously (per newer gradio version)
|
237 |
)
|
|
|
25 |
remove_trailing_punctuation,
|
26 |
build_symspell_obj,
|
27 |
symspeller,
|
|
|
28 |
)
|
29 |
|
30 |
from utils import (
|
|
|
44 |
my_cwd = str(cwd.resolve()) # string so it can be passed to os.path() objects
|
45 |
|
46 |
|
|
|
|
|
|
|
47 |
|
48 |
+
def chat(trivia_query):
|
49 |
history = []
|
50 |
+
response = ask_gpt(message=trivia_query, chat_pipe=my_chatbot)
|
51 |
history = [trivia_query, response]
|
52 |
html = ""
|
53 |
for item in history:
|
|
|
89 |
in_len = len(prompt)
|
90 |
if in_len > 512:
|
91 |
prompt = prompt[-512:] # truncate to 512 chars
|
92 |
+
print(f"Truncated prompt to last 512 chars: started with {in_len}")
|
93 |
max_len = min(max_len, 512)
|
94 |
|
95 |
resp = discussion(
|
|
|
113 |
else:
|
114 |
# no correction needed
|
115 |
cln_resp = rawtxt.strip()
|
116 |
+
bot_resp = corr(remove_repeated_words(cln_resp))
|
117 |
+
print(f"\nthe prompt was:\n\t{message}\nand the response was:\n\t{bot_resp}\n")
|
|
|
118 |
corr_rt = round(time.perf_counter() - gpt_et, 4)
|
119 |
print(
|
120 |
f"took {gpt_rt + corr_rt} sec to respond, {gpt_rt} for GPT, {corr_rt} for correction\n"
|
|
|
127 |
get_parser - a helper function for the argparse module
|
128 |
"""
|
129 |
parser = argparse.ArgumentParser(
|
130 |
+
description="submit a question, GPT model responds "
|
131 |
)
|
132 |
parser.add_argument(
|
133 |
"-m",
|
|
|
181 |
chat,
|
182 |
inputs=["text"],
|
183 |
outputs="html",
|
|
|
184 |
examples=[
|
185 |
"How many people inhabit Rhode Island?",
|
186 |
"What do you call the wheeled contraption which carries an airplane's luggage from place to place?",
|
|
|
192 |
"Who was Charles de Gaulle?",
|
193 |
"Where is Stonehenge located?",
|
194 |
"How many moons does Saturn have?",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
],
|
196 |
title=f"Ballpark Trivia: {default_model} Model",
|
197 |
description=f"Are you frequently asked google-able Trivia questions and annoyed by it? Well, this is the app for you! Ballpark Trivia Bot answers any trivia question with something that sounds plausible but is probably not 100% correct. \n\n One might say.. the answers are in the right ballpark.",
|
198 |
+
article="Further details can be found in the **[model card](https://huggingface.co/pszemraj/Ballpark-Trivia-XL)**.\n\n"
|
199 |
"**Important Notes & About:**\n\n"
|
200 |
"1. the model can take up to 60 seconds to respond sometimes, patience is a virtue.\n"
|
201 |
"2. the model started from a pretrained checkpoint, and was trained on several different datasets. Anything it says should be fact-checked before being regarded as a true statement.\n"
|
202 |
+
"3. Some params are still being tweaked (in future, will have them as inputs) any feedback is welcome :)\n",
|
203 |
css="""
|
204 |
.chatbox {display:flex;flex-direction:column}
|
205 |
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
|
|
208 |
""",
|
209 |
allow_screenshot=True,
|
210 |
allow_flagging="never",
|
211 |
+
theme="darkhuggingface",
|
212 |
)
|
213 |
|
214 |
# launch the gradio interface and start the server
|
215 |
iface.launch(
|
216 |
# prevent_thread_lock=True,
|
|
|
217 |
enable_queue=True, # also allows for dealing with multiple users simultaneously (per newer gradio version)
|
218 |
)
|