da03 commited on
Commit
6a29418
1 Parent(s): d8355b7
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import requests
4
+ import base64
5
+ import os
6
+
7
+ API_ENDPOINT = os.getenv('API_ENDPOINT')
8
+ API_KEY = os.getenv('API_KEY')
9
+
10
+ # setup
11
+ gallery = gr.Gallery(label="Rendered Image", show_label=False, elem_id="gallery").style(grid=[1], height="auto")
12
+
13
+ # infer
14
+ def infer(latex):
15
+ formula = latex
16
+ data = {'formula': formula, 'api_key': API_KEY}
17
+ with requests.post(url=API_ENDPOINT, data=data, timeout=600, stream=True) as r:
18
+ i = 0
19
+ for line in r.iter_lines():
20
+ response = line.decode('ascii').strip()
21
+ r = base64.decodebytes(response.encode('ascii'))
22
+ q = np.frombuffer(r, dtype=np.float32).reshape((64, 320))
23
+ i += 1
24
+ yield i, [q,]
25
+
26
+ title = "Markup-to-Image Diffusion Models with Scheduled Sampling"
27
+ description="Yuntian Deng, Noriyuki Kojima, Alexander M. Rush"
28
+
29
+ # launch
30
+ gr.Interface(fn=infer, inputs=["text"], outputs=[gr.Slider(0, 1000, value=0, label='step (out of 1000)'), gallery],title=title,description=description).queue(max_size=100).launch(enable_queue=True)