Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import os
|
|
6 |
import time
|
7 |
from PIL import Image
|
8 |
from deep_translator import GoogleTranslator
|
|
|
9 |
|
10 |
# Project by Nymbo
|
11 |
|
@@ -15,8 +16,8 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
15 |
timeout = 100
|
16 |
|
17 |
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
|
18 |
-
if prompt == "" or prompt
|
19 |
-
return None
|
20 |
|
21 |
key = random.randint(0, 999)
|
22 |
|
@@ -50,14 +51,10 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
|
|
50 |
image_bytes = response.content
|
51 |
image = Image.open(io.BytesIO(image_bytes))
|
52 |
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
53 |
-
|
54 |
-
# Save the image to a temporary file for download
|
55 |
-
temp_file = f"temp_generated_image_{key}.png"
|
56 |
-
image.save(temp_file, format="PNG")
|
57 |
-
return image, temp_file # Return both the image and the file path
|
58 |
except Exception as e:
|
59 |
print(f"Error when trying to open the image: {e}")
|
60 |
-
return None
|
61 |
|
62 |
css = """
|
63 |
#app-container {
|
@@ -87,20 +84,7 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
|
|
87 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
88 |
with gr.Row():
|
89 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
90 |
-
with gr.Row():
|
91 |
-
download_button = gr.File(label="Download Image", visible=False, elem_id="download-button")
|
92 |
|
93 |
-
|
94 |
-
def update_download_button(image, file):
|
95 |
-
if image is not None:
|
96 |
-
return gr.File.update(value=file, visible=True)
|
97 |
-
return gr.File.update(visible=False)
|
98 |
-
|
99 |
-
# Trigger the query function and update the image and download button
|
100 |
-
text_button.click(
|
101 |
-
query,
|
102 |
-
inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength],
|
103 |
-
outputs=[image_output, download_button]
|
104 |
-
)
|
105 |
|
106 |
app.launch(show_api=False, share=True)
|
|
|
6 |
import time
|
7 |
from PIL import Image
|
8 |
from deep_translator import GoogleTranslator
|
9 |
+
import json
|
10 |
|
11 |
# Project by Nymbo
|
12 |
|
|
|
16 |
timeout = 100
|
17 |
|
18 |
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
|
19 |
+
if prompt == "" or prompt == None:
|
20 |
+
return None
|
21 |
|
22 |
key = random.randint(0, 999)
|
23 |
|
|
|
51 |
image_bytes = response.content
|
52 |
image = Image.open(io.BytesIO(image_bytes))
|
53 |
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
54 |
+
return image
|
|
|
|
|
|
|
|
|
55 |
except Exception as e:
|
56 |
print(f"Error when trying to open the image: {e}")
|
57 |
+
return None
|
58 |
|
59 |
css = """
|
60 |
#app-container {
|
|
|
84 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
85 |
with gr.Row():
|
86 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
|
|
|
|
87 |
|
88 |
+
text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
app.launch(show_api=False, share=True)
|