Spaces:
Running
on
T4
Running
on
T4
da03
commited on
Commit
•
6e96524
1
Parent(s):
7fbd132
app.py
CHANGED
@@ -26,14 +26,17 @@ with gr.Blocks() as demo:
|
|
26 |
outputs = [slider, image, submit_btn]
|
27 |
def infer(formula):
|
28 |
data = {'formula': formula, 'api_key': API_KEY}
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
submit_btn.click(fn=infer, inputs=inputs, outputs=outputs)
|
39 |
demo.queue(concurrency_count=20, max_size=200).launch(enable_queue=True)
|
|
|
26 |
outputs = [slider, image, submit_btn]
|
27 |
def infer(formula):
|
28 |
data = {'formula': formula, 'api_key': API_KEY}
|
29 |
+
try:
|
30 |
+
with requests.post(url=API_ENDPOINT, data=data, timeout=600, stream=True) as r:
|
31 |
+
i = 0
|
32 |
+
for line in r.iter_lines():
|
33 |
+
response = line.decode('ascii').strip()
|
34 |
+
r = base64.decodebytes(response.encode('ascii'))
|
35 |
+
q = np.frombuffer(r, dtype=np.float32).reshape((64, 320, 3))
|
36 |
+
i += 1
|
37 |
+
yield i, q, submit_btn.update(visible=False)
|
38 |
+
yield i, q, submit_btn.update(visible=True)
|
39 |
+
except Exception as e:
|
40 |
+
yield 1000, 255*np.ones((64, 320, 3)), submit_btn.update(visible=True)
|
41 |
submit_btn.click(fn=infer, inputs=inputs, outputs=outputs)
|
42 |
demo.queue(concurrency_count=20, max_size=200).launch(enable_queue=True)
|