Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
# Custom CSS for better styling
|
5 |
+
custom_css = """
|
6 |
+
.gradio-container {
|
7 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
8 |
+
}
|
9 |
+
.generate-btn {
|
10 |
+
background: rgb(99, 102, 241) !important;
|
11 |
+
color: white !important;
|
12 |
+
border: none !important;
|
13 |
+
}
|
14 |
+
.generate-btn:hover {
|
15 |
+
background: rgb(67, 56, 202) !important;
|
16 |
+
transform: translateY(-2px);
|
17 |
+
transition: all 0.2s;
|
18 |
+
}
|
19 |
+
.container {
|
20 |
+
max-width: 900px;
|
21 |
+
margin: 0 auto;
|
22 |
+
padding: 20px;
|
23 |
+
}
|
24 |
+
.tips {
|
25 |
+
background: #f0f9ff;
|
26 |
+
padding: 20px;
|
27 |
+
border-radius: 10px;
|
28 |
+
margin: 20px 0;
|
29 |
+
border: 1px solid #bae6fd;
|
30 |
+
}
|
31 |
+
"""
|
32 |
+
|
33 |
+
# Example prompts for the dropdown
|
34 |
+
example_prompts = [
|
35 |
+
"A magical forest at twilight with glowing mushrooms, digital art style",
|
36 |
+
"A futuristic cityscape with flying cars, neon lights, cyberpunk style",
|
37 |
+
"A cozy cafe interior with steam rising from coffee cups, warm lighting",
|
38 |
+
"An underwater scene with bioluminescent creatures, deep sea atmosphere",
|
39 |
+
"A steampunk-inspired flying machine in the clouds, vintage style"
|
40 |
+
]
|
41 |
+
|
42 |
+
def generate_image(prompt):
|
43 |
+
# This is where you'd integrate with the Black Forest Labs model
|
44 |
+
# For now, we'll just create an iframe to their space
|
45 |
+
iframe_html = f'<iframe src="https://black-forest-labs-flux-1-dev.hf.space" frameborder="0" width="100%" height="450"></iframe>'
|
46 |
+
return iframe_html
|
47 |
+
|
48 |
+
# Create the Gradio interface
|
49 |
+
with gr.Blocks(css=custom_css) as demo:
|
50 |
+
gr.HTML("<div class='container'>")
|
51 |
+
gr.HTML("""
|
52 |
+
<header style="text-align: center; margin-bottom: 2rem;">
|
53 |
+
<h1 style="font-size: 2.5rem; color: rgb(99, 102, 241); margin-bottom: 1rem;">
|
54 |
+
AI Image Generator
|
55 |
+
</h1>
|
56 |
+
<p style="color: #6b7280; font-size: 1.1rem;">
|
57 |
+
Create amazing AI-generated images with Stable Diffusion
|
58 |
+
</p>
|
59 |
+
<p style="color: #6b7280;">
|
60 |
+
Powered by Black Forest Labs
|
61 |
+
</p>
|
62 |
+
</header>
|
63 |
+
""")
|
64 |
+
|
65 |
+
with gr.Column():
|
66 |
+
# Add example prompts dropdown
|
67 |
+
prompt_dropdown = gr.Dropdown(
|
68 |
+
choices=example_prompts,
|
69 |
+
label="Example Prompts (Click to use)",
|
70 |
+
info="Select a prompt to try out"
|
71 |
+
)
|
72 |
+
|
73 |
+
# Text input for the prompt
|
74 |
+
prompt_input = gr.Textbox(
|
75 |
+
label="Enter your prompt",
|
76 |
+
placeholder="Describe the image you want to generate...",
|
77 |
+
lines=3
|
78 |
+
)
|
79 |
+
|
80 |
+
# Generate button
|
81 |
+
generate_btn = gr.Button("Generate Image", elem_classes=["generate-btn"])
|
82 |
+
|
83 |
+
# Output area for the iframe
|
84 |
+
output = gr.HTML()
|
85 |
+
|
86 |
+
# Tips section
|
87 |
+
gr.HTML("""
|
88 |
+
<div class="tips">
|
89 |
+
<h2 style="font-size: 1.25rem; color: #0369a1; margin-bottom: 1rem;">
|
90 |
+
Tips for Best Results
|
91 |
+
</h2>
|
92 |
+
<ul style="list-style-type: disc; padding-left: 1.5rem; color: #0c4a6e;">
|
93 |
+
<li>Be specific in your descriptions - include details about style, mood, and composition</li>
|
94 |
+
<li>Try adding artistic styles like "oil painting", "watercolor", or "digital art"</li>
|
95 |
+
<li>Include lighting descriptions like "sunset", "studio lighting", or "moonlight"</li>
|
96 |
+
<li>Experiment with different perspectives: "close-up", "aerial view", or "wide angle"</li>
|
97 |
+
<li>Add quality enhancers like "highly detailed", "4K", or "professional photography"</li>
|
98 |
+
</ul>
|
99 |
+
</div>
|
100 |
+
""")
|
101 |
+
|
102 |
+
gr.HTML("</div>")
|
103 |
+
|
104 |
+
# Set up event handlers
|
105 |
+
prompt_dropdown.change(
|
106 |
+
lambda x: x,
|
107 |
+
inputs=prompt_dropdown,
|
108 |
+
outputs=prompt_input
|
109 |
+
)
|
110 |
+
|
111 |
+
generate_btn.click(
|
112 |
+
generate_image,
|
113 |
+
inputs=prompt_input,
|
114 |
+
outputs=output
|
115 |
+
)
|
116 |
+
|
117 |
+
# Launch the app
|
118 |
+
demo.launch()
|