Spaces:
Runtime error
Runtime error
Update app.py
#1
by
soiz1
- opened
app.py
CHANGED
@@ -2,25 +2,37 @@ import gradio as gr
|
|
2 |
import random
|
3 |
import requests
|
4 |
import io
|
5 |
-
from PIL import Image
|
6 |
import os
|
7 |
|
8 |
-
|
9 |
API_URL = "https://api-inference.huggingface.co/models/LucyintheSky/lucy-dream-lora"
|
10 |
headers = {"Authorization": "Bearer " + os.environ.get('TOKEN')}
|
11 |
|
12 |
def query(payload):
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def generate(prompt):
|
17 |
image_bytes = query({
|
18 |
-
|
19 |
-
"parameters"
|
20 |
-
"seed": random.randint(0,9999999)}
|
21 |
})
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
theme = gr.themes.Base(
|
26 |
primary_hue="gray",
|
@@ -38,17 +50,20 @@ with gr.Blocks(theme=theme) as demo:
|
|
38 |
<center> <img src="https://cdn-uploads.huggingface.co/production/uploads/650a1281b48ff3906647edd0/rbzPKW_p5XTG9leEO4uFt.png" > </center>
|
39 |
<br><br><br>
|
40 |
""")
|
41 |
-
img = gr.Image(show_label=False, type=
|
42 |
-
textbox = gr.Textbox(show_label=False, placeholder='
|
43 |
-
button = gr.Button("
|
44 |
|
45 |
gr.Examples(
|
46 |
-
[["Emma Stone on prom night, mint green satin maxi dress"],
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
)
|
|
|
52 |
|
53 |
gr.Markdown("""
|
54 |

|
|
|
2 |
import random
|
3 |
import requests
|
4 |
import io
|
5 |
+
from PIL import Image, UnidentifiedImageError
|
6 |
import os
|
7 |
|
|
|
8 |
API_URL = "https://api-inference.huggingface.co/models/LucyintheSky/lucy-dream-lora"
|
9 |
headers = {"Authorization": "Bearer " + os.environ.get('TOKEN')}
|
10 |
|
11 |
def query(payload):
|
12 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
13 |
+
if response.ok:
|
14 |
+
return response.content
|
15 |
+
else:
|
16 |
+
print("API Error:", response.status_code, response.text)
|
17 |
+
return None
|
18 |
|
19 |
def generate(prompt):
|
20 |
image_bytes = query({
|
21 |
+
"inputs": f"lucy dream style {prompt}, perfect body, beautiful face, perfect skin",
|
22 |
+
"parameters": {"negative_prompt": "ugly, deformed, deformed face, ugly face, bad quality",
|
23 |
+
"seed": random.randint(0, 9999999)}
|
24 |
})
|
25 |
+
|
26 |
+
if image_bytes is None:
|
27 |
+
return "Error: Could not generate image. Please try again."
|
28 |
+
|
29 |
+
try:
|
30 |
+
image = Image.open(io.BytesIO(image_bytes))
|
31 |
+
image_path = "temp_output.png"
|
32 |
+
image.save(image_path)
|
33 |
+
return image_path
|
34 |
+
except UnidentifiedImageError:
|
35 |
+
return "Error: Invalid image data received."
|
36 |
|
37 |
theme = gr.themes.Base(
|
38 |
primary_hue="gray",
|
|
|
50 |
<center> <img src="https://cdn-uploads.huggingface.co/production/uploads/650a1281b48ff3906647edd0/rbzPKW_p5XTG9leEO4uFt.png" > </center>
|
51 |
<br><br><br>
|
52 |
""")
|
53 |
+
img = gr.Image(show_label=False, type="filepath")
|
54 |
+
textbox = gr.Textbox(show_label=False, placeholder='Type your prompt here')
|
55 |
+
button = gr.Button("Generate", variant="primary")
|
56 |
|
57 |
gr.Examples(
|
58 |
+
[["Emma Stone on prom night, mint green satin maxi dress"],
|
59 |
+
["Lady Gaga, 50s hair style, prom night"],
|
60 |
+
["Rihanna wearing a silver prom dress with crystal jewelry"]],
|
61 |
+
inputs=textbox,
|
62 |
+
outputs=img,
|
63 |
+
fn=generate,
|
64 |
+
cache_examples=False # γγ£γγ·γ₯ζ©θ½γγͺγγ«γγ
|
65 |
)
|
66 |
+
|
67 |
|
68 |
gr.Markdown("""
|
69 |

|