Spaces:
Running
on
T4
Running
on
T4
da03
commited on
Commit
·
de88b8c
1
Parent(s):
ed21af3
app.py
CHANGED
|
@@ -7,24 +7,31 @@ import os
|
|
| 7 |
API_ENDPOINT = os.getenv('API_ENDPOINT')
|
| 8 |
API_KEY = os.getenv('API_KEY')
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
API_ENDPOINT = os.getenv('API_ENDPOINT')
|
| 8 |
API_KEY = os.getenv('API_KEY')
|
| 9 |
|
| 10 |
+
title = "<h1><center>Markup-to-Image Diffusion Models with Scheduled Sampling</center></h1>"
|
| 11 |
+
description = "<center>Yuntian Deng, Noriyuki Kojima, Alexander M. Rush</center>"
|
| 12 |
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown(title)
|
| 15 |
+
gr.Markdown(description)
|
| 16 |
+
with gr.Row():
|
| 17 |
+
with gr.Column(scale=2):
|
| 18 |
+
textbox = gr.Textbox(label="LaTeX", lines=1, max_lines=1, placeholder='Type LaTeX formula here and click "Generate"')
|
| 19 |
+
submit_btn = gr.Button("Generate", elem_id="btn")
|
| 20 |
+
with gr.Column(scale=3):
|
| 21 |
+
slider = gr.Slider(0, 1000, value=0, label='step (out of 1000)')
|
| 22 |
+
image = gr.Image(label="Rendered Image", show_label=False, elem_id="image")
|
| 23 |
+
inputs = [textbox]
|
| 24 |
+
outputs = [slider, image, submit_btn]
|
| 25 |
+
def infer(formula):
|
| 26 |
+
data = {'formula': formula, 'api_key': API_KEY}
|
| 27 |
+
with requests.post(url=API_ENDPOINT, data=data, timeout=600, stream=True) as r:
|
| 28 |
+
i = 0
|
| 29 |
+
for line in r.iter_lines():
|
| 30 |
+
response = line.decode('ascii').strip()
|
| 31 |
+
r = base64.decodebytes(response.encode('ascii'))
|
| 32 |
+
q = np.frombuffer(r, dtype=np.float32).reshape((64, 320, 3))
|
| 33 |
+
i += 1
|
| 34 |
+
yield i, q, submit_btn.update(visible=False)
|
| 35 |
+
yield i, q, submit_btn.update(visible=True)
|
| 36 |
+
submit_btn.click(fn=infer, inputs=inputs, outputs=outputs)
|
| 37 |
+
demo.queue(concurrency_count=20, max_size=200).launch(enable_queue=True)
|