Omnibus commited on
Commit
d3a8ff8
1 Parent(s): af5c7ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -3
app.py CHANGED
@@ -5,7 +5,7 @@ import requests
5
  import uuid
6
  import io
7
  import base64
8
-
9
 
10
  loaded_model=[]
11
  for i,model in enumerate(models):
@@ -16,7 +16,7 @@ for i,model in enumerate(models):
16
  pass
17
  print (loaded_model)
18
 
19
- def run_dif(out_prompt):
20
  out_box=[]
21
  out_html=""
22
  for i,ea in enumerate(loaded_model):
@@ -47,6 +47,49 @@ def run_dif(out_prompt):
47
  html_out = "<div class='grid_class'>"+out_html+"</div>"
48
 
49
  yield out_box,html_out
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  css="""
51
  .grid_class{
52
  display:flex;
@@ -62,5 +105,5 @@ with gr.Blocks(css=css) as app:
62
  out_html=gr.HTML()
63
  outp=gr.Gallery()
64
  btn=gr.Button()
65
- btn.click(run_dif,inp,[outp,out_html])
66
  app.launch()
 
5
  import uuid
6
  import io
7
  import base64
8
+ import threading
9
 
10
  loaded_model=[]
11
  for i,model in enumerate(models):
 
16
  pass
17
  print (loaded_model)
18
 
19
+ def run_dif(out_prompt,mod):
20
  out_box=[]
21
  out_html=""
22
  for i,ea in enumerate(loaded_model):
 
47
  html_out = "<div class='grid_class'>"+out_html+"</div>"
48
 
49
  yield out_box,html_out
50
+
51
+ def thread_dif(out_prompt,mod):
52
+ out_box=[]
53
+ out_html=""
54
+ #for i,ea in enumerate(loaded_model):
55
+ try:
56
+ print (ea)
57
+ model=loaded_model[int(mod)]
58
+ out_img=model(out_prompt)
59
+ print(out_img)
60
+ url=f'https://omnibus-top-20.hf.space/file={out_img}'
61
+ print(url)
62
+ uid = uuid.uuid4()
63
+ #urllib.request.urlretrieve(image, 'tmp.png')
64
+ #out=Image.open('tmp.png')
65
+ r = requests.get(url, stream=True)
66
+
67
+ if r.status_code == 200:
68
+ img_buffer = io.BytesIO(r.content)
69
+ print (f'bytes:: {io.BytesIO(r.content)}')
70
+ str_equivalent_image = base64.b64encode(img_buffer.getvalue()).decode()
71
+ img_tag = "<img src='data:image/png;base64," + str_equivalent_image + "'/>"
72
+ out_html+=f"<div class='img_class'><a href='https://huggingface.co/models/{models[i]}'>{models[i]}</a><br>"+img_tag+"</div>"
73
+ out = Image.open(io.BytesIO(r.content))
74
+ out_box.append(out)
75
+ html_out = "<div class='grid_class'>"+out_html+"</div>"
76
+ yield out_box,html_out
77
+ except Exception as e:
78
+ out_html+=str(e)
79
+ html_out = "<div class='grid_class'>"+out_html+"</div>"
80
+
81
+ yield out_box,html_out
82
+
83
+
84
+
85
+ def start_threads(prompt):
86
+ t1 = threading.Thread(target=thread_dif, args=(prompt,0))
87
+ t2 = threading.Thread(target=thread_dif, args=(prompt,1))
88
+ t1.start()
89
+ t2.start()
90
+ print (t1)
91
+ print (t2)
92
+
93
  css="""
94
  .grid_class{
95
  display:flex;
 
105
  out_html=gr.HTML()
106
  outp=gr.Gallery()
107
  btn=gr.Button()
108
+ btn.click(start_threads,inp,[outp,out_html])
109
  app.launch()