Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,8 +14,8 @@ from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_
|
|
| 14 |
from io import BytesIO
|
| 15 |
import base64
|
| 16 |
from diffusers.pipelines.flux.pipeline_flux import FluxPipeline
|
| 17 |
-
|
| 18 |
-
import
|
| 19 |
os.environ['HF_HUB_DOWNLOAD_TIMEOUT'] = '120'
|
| 20 |
dtype = torch.bfloat16
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -149,65 +149,56 @@ Lighting: Time of day, intensity, direction (e.g., backlighting).
|
|
| 149 |
except Exception as e:
|
| 150 |
enhanced = f"Error enhancing prompt: {str(e)}"
|
| 151 |
return enhanced
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
audio_data = r.record(source)
|
| 158 |
-
text = r.recognize_google(audio_data)
|
| 159 |
-
except Exception as e:
|
| 160 |
-
text = f"Transcription error: {str(e)}"
|
| 161 |
-
return text
|
| 162 |
-
|
| 163 |
-
# --- Gradio Interface with Enhanced UI and Voice Recognition ---
|
| 164 |
-
custom_css = """
|
| 165 |
#col-container {
|
| 166 |
margin: 0 auto;
|
| 167 |
-
max-width:
|
| 168 |
-
padding: 20px;
|
| 169 |
}
|
| 170 |
-
.user-msg { background: #e3f2fd; border-radius: 15px; padding: 10px; margin: 5px; }
|
| 171 |
-
.bot-msg { background: #f5f5f5; border-radius: 15px; padding: 10px; margin: 5px; }
|
| 172 |
"""
|
| 173 |
|
| 174 |
-
with gr.Blocks(css=
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
| 211 |
generation_event = run_button.click(
|
| 212 |
fn=infer,
|
| 213 |
inputs=[enhanced_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
|
|
|
| 14 |
from io import BytesIO
|
| 15 |
import base64
|
| 16 |
from diffusers.pipelines.flux.pipeline_flux import FluxPipeline
|
| 17 |
+
import torch.nn.functional as F
|
| 18 |
+
import torch.nn as nn
|
| 19 |
os.environ['HF_HUB_DOWNLOAD_TIMEOUT'] = '120'
|
| 20 |
dtype = torch.bfloat16
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 149 |
except Exception as e:
|
| 150 |
enhanced = f"Error enhancing prompt: {str(e)}"
|
| 151 |
return enhanced
|
| 152 |
+
def fake_typing():
|
| 153 |
+
for _ in range(3):
|
| 154 |
+
yield {"visible": False}, {"visible": True}
|
| 155 |
+
time.sleep(0.5)
|
| 156 |
+
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
#col-container {
|
| 158 |
margin: 0 auto;
|
| 159 |
+
max-width: 520px;
|
|
|
|
| 160 |
}
|
|
|
|
|
|
|
| 161 |
"""
|
| 162 |
|
| 163 |
+
with gr.Blocks(css="""
|
| 164 |
+
.user-msg { background: #e3f2fd; border-radius: 15px; padding: 10px; margin: 5px; }
|
| 165 |
+
.bot-msg { background: #f5f5f5; border-radius: 15px; padding: 10px; margin: 5px; }
|
| 166 |
+
""") as demo:
|
| 167 |
+
chatbot = gr.Chatbot(elem_classes=["user-msg", "bot-msg"])
|
| 168 |
+
history_state = gr.State([])
|
| 169 |
+
with gr.Column(elem_id="col-container"):
|
| 170 |
+
gr.Markdown("# FLUX.1 [dev] with History Tracking")
|
| 171 |
+
gr.Markdown("### Step 1: Enhance Your Prompt")
|
| 172 |
+
original_prompt = gr.Textbox(label="Original Prompt", lines=2)
|
| 173 |
+
enhance_button = gr.Button("Enhance Prompt")
|
| 174 |
+
enhanced_prompt = gr.Textbox(label="Enhanced Prompt (Editable)", lines=2)
|
| 175 |
+
enhance_button.click(enhance_prompt, original_prompt, enhanced_prompt)
|
| 176 |
+
gr.Markdown("### Step 2: Generate Image")
|
| 177 |
+
with gr.Row():
|
| 178 |
+
run_button = gr.Button("Generate Image", variant="primary")
|
| 179 |
+
result = gr.Image(label="Result", show_label=False)
|
| 180 |
+
with gr.Accordion("Advanced Settings"):
|
| 181 |
+
seed = gr.Slider(0, MAX_SEED, value=0, label="Seed")
|
| 182 |
+
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
| 183 |
+
with gr.Row():
|
| 184 |
+
width = gr.Slider(256, MAX_IMAGE_SIZE, 1024, step=32, label="Width")
|
| 185 |
+
height = gr.Slider(256, MAX_IMAGE_SIZE, 1024, step=32, label="Height")
|
| 186 |
+
with gr.Row():
|
| 187 |
+
guidance_scale = gr.Slider(1, 15, 3.5, step=0.1, label="Guidance Scale")
|
| 188 |
+
num_inference_steps = gr.Slider(1, 50, 28, step=1, label="Inference Steps")
|
| 189 |
+
with gr.Accordion("Generation History", open=False):
|
| 190 |
+
history_display = gr.HTML("<p style='margin: 20px;'>No generations yet</p>")
|
| 191 |
+
gr.Examples(
|
| 192 |
+
examples=[
|
| 193 |
+
"a tiny astronaut hatching from an egg on the moon",
|
| 194 |
+
"a cat holding a sign that says hello world",
|
| 195 |
+
"an anime illustration of a wiener schnitzel",
|
| 196 |
+
],
|
| 197 |
+
inputs=enhanced_prompt,
|
| 198 |
+
outputs=[result, seed],
|
| 199 |
+
fn=infer,
|
| 200 |
+
cache_examples="lazy"
|
| 201 |
+
)
|
| 202 |
generation_event = run_button.click(
|
| 203 |
fn=infer,
|
| 204 |
inputs=[enhanced_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|