Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -78,9 +78,29 @@ st.write("**It might take a while to return an output on the first 'generate' cl
|
|
78 |
st.write("**For convenience, you can use chatgpt to copy text and evaluate model output.**")
|
79 |
st.write("-" * 50)
|
80 |
|
81 |
-
async def generate_from_api(user_input, generation_config):
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
payload = {
|
85 |
"prompt": user_input,
|
86 |
"config": generation_config
|
@@ -89,10 +109,19 @@ async def generate_from_api(user_input, generation_config):
|
|
89 |
headers = {
|
90 |
'Content-Type': 'application/json'
|
91 |
}
|
92 |
-
|
93 |
async with aiohttp.ClientSession() as session:
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
|
98 |
# Sample texts
|
@@ -171,7 +200,7 @@ def wrap_text(text, task_value):
|
|
171 |
# Text input
|
172 |
user_input = st.text_area("Enter text below **(PLEASE, FIRST READ THE INSTRUCTIONS ON HOW TO USE IN THE SIDE BAR FOR BETTER EXPERIENCE)**: ", sample_texts[sample_text])
|
173 |
user_input = instruction_wrap.get(sample_texts.get(user_input, user_input), user_input)
|
174 |
-
|
175 |
if st.button("Generate"):
|
176 |
if user_input:
|
177 |
try:
|
@@ -191,6 +220,11 @@ if st.button("Generate"):
|
|
191 |
input_ids = tokenizer(wrapped_input, return_tensors="pt")["input_ids"].to(device)
|
192 |
output = model.generate(input_ids, **generation_config)
|
193 |
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
generated_text = re.sub(r"\|(end_f_text|end_of_text|end_ofext|end_oftext)", " ", generated_text.split("|end_of_text|")[0])
|
196 |
full_output = st.empty()
|
|
|
78 |
st.write("**For convenience, you can use chatgpt to copy text and evaluate model output.**")
|
79 |
st.write("-" * 50)
|
80 |
|
81 |
+
# async def generate_from_api(user_input, generation_config):
|
82 |
+
# url = "https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict"
|
83 |
+
|
84 |
+
# payload = {
|
85 |
+
# "prompt": user_input,
|
86 |
+
# "config": generation_config
|
87 |
+
# }
|
88 |
|
89 |
+
# headers = {
|
90 |
+
# 'Content-Type': 'application/json'
|
91 |
+
# }
|
92 |
+
|
93 |
+
# async with aiohttp.ClientSession() as session:
|
94 |
+
# async with session.post(url, headers=headers, json=payload) as response:
|
95 |
+
# return await response.text()
|
96 |
+
|
97 |
+
async def generate_from_api(user_input, generation_config):
|
98 |
+
urls = [
|
99 |
+
"https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict",
|
100 |
+
"https://daveokpare--sabiyarn-fastapi-app.modal.run/predict",
|
101 |
+
# "https://pauljeffrey_-sabiyarn-fastapi-app.modal.run/predict"
|
102 |
+
]
|
103 |
+
|
104 |
payload = {
|
105 |
"prompt": user_input,
|
106 |
"config": generation_config
|
|
|
109 |
headers = {
|
110 |
'Content-Type': 'application/json'
|
111 |
}
|
112 |
+
|
113 |
async with aiohttp.ClientSession() as session:
|
114 |
+
for url in urls:
|
115 |
+
try:
|
116 |
+
async with session.post(url, headers=headers, json=payload) as response:
|
117 |
+
if response.status == 200:
|
118 |
+
return await response.text()
|
119 |
+
else:
|
120 |
+
print(f"Failed to fetch from {url} with status code {response.status}")
|
121 |
+
except Exception as e:
|
122 |
+
print(f"Error fetching from {url}: {e}")
|
123 |
+
|
124 |
+
return "FAILED"
|
125 |
|
126 |
|
127 |
# Sample texts
|
|
|
200 |
# Text input
|
201 |
user_input = st.text_area("Enter text below **(PLEASE, FIRST READ THE INSTRUCTIONS ON HOW TO USE IN THE SIDE BAR FOR BETTER EXPERIENCE)**: ", sample_texts[sample_text])
|
202 |
user_input = instruction_wrap.get(sample_texts.get(user_input, user_input), user_input)
|
203 |
+
print("Final user input: ", user_input)
|
204 |
if st.button("Generate"):
|
205 |
if user_input:
|
206 |
try:
|
|
|
220 |
input_ids = tokenizer(wrapped_input, return_tensors="pt")["input_ids"].to(device)
|
221 |
output = model.generate(input_ids, **generation_config)
|
222 |
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
223 |
+
|
224 |
+
if generated_text == "FAILED":
|
225 |
+
input_ids = tokenizer(wrapped_input, return_tensors="pt")["input_ids"].to(device)
|
226 |
+
output = model.generate(input_ids, **generation_config)
|
227 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
228 |
|
229 |
generated_text = re.sub(r"\|(end_f_text|end_of_text|end_ofext|end_oftext)", " ", generated_text.split("|end_of_text|")[0])
|
230 |
full_output = st.empty()
|