Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ from PIL import Image
|
|
4 |
import requests
|
5 |
import uuid
|
6 |
import io
|
|
|
|
|
7 |
|
8 |
loaded_model=[]
|
9 |
for i,model in enumerate(models):
|
@@ -16,6 +18,7 @@ print (loaded_model)
|
|
16 |
|
17 |
def run_dif(out_prompt):
|
18 |
out_box=[]
|
|
|
19 |
for i,ea in enumerate(loaded_model):
|
20 |
try:
|
21 |
print (ea)
|
@@ -28,16 +31,23 @@ def run_dif(out_prompt):
|
|
28 |
#urllib.request.urlretrieve(image, 'tmp.png')
|
29 |
#out=Image.open('tmp.png')
|
30 |
r = requests.get(url, stream=True)
|
|
|
31 |
if r.status_code == 200:
|
|
|
32 |
print (f'bytes:: {io.BytesIO(r.content)}')
|
|
|
|
|
|
|
33 |
out = Image.open(io.BytesIO(r.content))
|
34 |
out_box.append(out)
|
35 |
-
|
|
|
36 |
except Exception:
|
37 |
-
yield out_box
|
38 |
with gr.Blocks() as app:
|
39 |
inp=gr.Textbox()
|
|
|
40 |
outp=gr.Gallery()
|
41 |
btn=gr.Button()
|
42 |
-
btn.click(run_dif,inp,outp)
|
43 |
app.launch()
|
|
|
4 |
import requests
|
5 |
import uuid
|
6 |
import io
|
7 |
+
import base64
|
8 |
+
|
9 |
|
10 |
loaded_model=[]
|
11 |
for i,model in enumerate(models):
|
|
|
18 |
|
19 |
def run_dif(out_prompt):
|
20 |
out_box=[]
|
21 |
+
out_html=""
|
22 |
for i,ea in enumerate(loaded_model):
|
23 |
try:
|
24 |
print (ea)
|
|
|
31 |
#urllib.request.urlretrieve(image, 'tmp.png')
|
32 |
#out=Image.open('tmp.png')
|
33 |
r = requests.get(url, stream=True)
|
34 |
+
|
35 |
if r.status_code == 200:
|
36 |
+
img_buffer = io.BytesIO(r.content)
|
37 |
print (f'bytes:: {io.BytesIO(r.content)}')
|
38 |
+
str_equivalent_image = base64.b64encode(img_buffer.getvalue()).decode()
|
39 |
+
img_tag = "<img src='data:image/png;base64," + str_equivalent_image + "'/>"
|
40 |
+
out_html+=out_html+"<div>"+img_tag+"</div>"
|
41 |
out = Image.open(io.BytesIO(r.content))
|
42 |
out_box.append(out)
|
43 |
+
|
44 |
+
yield out_box,out_html
|
45 |
except Exception:
|
46 |
+
yield out_box,out_html
|
47 |
with gr.Blocks() as app:
|
48 |
inp=gr.Textbox()
|
49 |
+
out_html=gr.HTML()
|
50 |
outp=gr.Gallery()
|
51 |
btn=gr.Button()
|
52 |
+
btn.click(run_dif,inp,[outp,out_html])
|
53 |
app.launch()
|