Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,9 @@ from PIL import Image
|
|
3 |
import requests
|
4 |
import io
|
5 |
import base64
|
|
|
6 |
|
7 |
-
# List of models
|
8 |
models = [
|
9 |
"dreamlike-art/dreamlike-photoreal-2.0",
|
10 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
@@ -69,59 +70,75 @@ models = [
|
|
69 |
"Yntec/epiCPhotoGasm",
|
70 |
]
|
71 |
|
72 |
-
#
|
73 |
-
|
|
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
try:
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
failed_models.append(model_name)
|
91 |
except Exception as e:
|
92 |
-
print(
|
93 |
-
|
94 |
|
95 |
-
|
|
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
<img src='data:image/png;base64,{img_str}' style="max-width: 200px;" />
|
109 |
-
</div>
|
110 |
-
"""
|
111 |
-
|
112 |
-
failed_html = "<ul>" + "".join(f"<li>{model}</li>" for model in failed_models) + "</ul>"
|
113 |
-
return images_html, f"<h3>Failed Models:</h3>{failed_html}"
|
114 |
|
115 |
-
|
116 |
-
with gr.Blocks() as app:
|
117 |
with gr.Row():
|
118 |
with gr.Column():
|
119 |
-
|
120 |
-
|
121 |
-
with gr.Column():
|
122 |
-
output_html = gr.HTML(label="Generated Images")
|
123 |
-
failed_html = gr.HTML(label="Failed Models")
|
124 |
|
125 |
-
|
|
|
|
|
126 |
|
127 |
app.launch()
|
|
|
3 |
import requests
|
4 |
import io
|
5 |
import base64
|
6 |
+
import threading
|
7 |
|
8 |
+
# List of models
|
9 |
models = [
|
10 |
"dreamlike-art/dreamlike-photoreal-2.0",
|
11 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
|
|
70 |
"Yntec/epiCPhotoGasm",
|
71 |
]
|
72 |
|
73 |
+
# Load models
|
74 |
+
loaded_models = []
|
75 |
+
available_models = []
|
76 |
|
77 |
+
for model in models:
|
78 |
+
try:
|
79 |
+
loaded_models.append(gr.load(f'models/{model}'))
|
80 |
+
available_models.append(model)
|
81 |
+
except Exception as e:
|
82 |
+
print(f"Model {model} could not be loaded: {e}")
|
83 |
+
|
84 |
+
print(loaded_models)
|
85 |
+
print(available_models)
|
86 |
+
|
87 |
+
def generate_image(prompt, model_index):
|
88 |
+
try:
|
89 |
+
model = loaded_models[model_index]
|
90 |
+
out_img = model(prompt)
|
91 |
+
print(out_img)
|
92 |
+
return out_img
|
93 |
+
except Exception as e:
|
94 |
+
print(e)
|
95 |
+
return None
|
96 |
+
|
97 |
+
def run_all_models(prompt):
|
98 |
+
out_box = []
|
99 |
+
out_html = ""
|
100 |
+
|
101 |
+
for i, model in enumerate(loaded_models):
|
102 |
try:
|
103 |
+
out_img = generate_image(prompt, i)
|
104 |
+
if out_img:
|
105 |
+
raw = Image.open(out_img)
|
106 |
+
raw = raw.convert('RGB')
|
107 |
+
out_box.append(raw)
|
108 |
|
109 |
+
# Convert image to base64 for HTML display
|
110 |
+
buffered = io.BytesIO()
|
111 |
+
raw.save(buffered, format="PNG")
|
112 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
113 |
+
img_tag = f"<img src='data:image/png;base64,{img_str}'/>"
|
114 |
+
out_html += f"<div class='img_class'><a href='https://huggingface.co/models/{available_models[i]}'>{available_models[i]}</a><br>{img_tag}</div>"
|
|
|
115 |
except Exception as e:
|
116 |
+
print(e)
|
117 |
+
out_html += f"<div class='img_class'>{available_models[i]}: {str(e)}</div>"
|
118 |
|
119 |
+
html_out = f"<div class='grid_class'>{out_html}</div>"
|
120 |
+
return out_box, html_out
|
121 |
|
122 |
+
css = """
|
123 |
+
.grid_class {
|
124 |
+
display: flex;
|
125 |
+
flex-wrap: wrap;
|
126 |
+
gap: 10px;
|
127 |
+
}
|
128 |
+
.img_class {
|
129 |
+
min-width: 200px;
|
130 |
+
margin: 5px;
|
131 |
+
}
|
132 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as app:
|
|
|
135 |
with gr.Row():
|
136 |
with gr.Column():
|
137 |
+
inp = gr.Textbox(label="Prompt")
|
138 |
+
btn = gr.Button("Generate Images")
|
|
|
|
|
|
|
139 |
|
140 |
+
out_html = gr.HTML()
|
141 |
+
outp = gr.Gallery()
|
142 |
+
btn.click(run_all_models, [inp], [outp, out_html])
|
143 |
|
144 |
app.launch()
|