Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,116 +1,41 @@
|
|
1 |
import gradio as gr
|
2 |
-
import requests
|
3 |
-
import io
|
4 |
-
import random
|
5 |
-
import os
|
6 |
-
import time
|
7 |
-
from PIL import Image
|
8 |
-
from deep_translator import GoogleTranslator
|
9 |
-
import json
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
"
|
44 |
-
"
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
# Send the request to the API and handle the response
|
51 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
52 |
-
if response.status_code != 200:
|
53 |
-
print(f"Error: Failed to get image. Response status: {response.status_code}")
|
54 |
-
print(f"Response content: {response.text}")
|
55 |
-
if response.status_code == 503:
|
56 |
-
raise gr.Error(f"{response.status_code} : The model is being loaded")
|
57 |
-
raise gr.Error(f"{response.status_code}")
|
58 |
-
|
59 |
-
try:
|
60 |
-
# Convert the response content into an image
|
61 |
-
image_bytes = response.content
|
62 |
-
image = Image.open(io.BytesIO(image_bytes))
|
63 |
-
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
64 |
-
return image
|
65 |
-
except Exception as e:
|
66 |
-
print(f"Error when trying to open the image: {e}")
|
67 |
-
return None
|
68 |
-
|
69 |
-
# CSS to style the app
|
70 |
-
css = """
|
71 |
-
#app-container {
|
72 |
-
max-width: 800px;
|
73 |
-
margin-left: auto;
|
74 |
-
margin-right: auto;
|
75 |
-
}
|
76 |
-
"""
|
77 |
-
|
78 |
-
# Build the Gradio UI with Blocks
|
79 |
-
with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
|
80 |
-
# Add a title to the app
|
81 |
-
gr.HTML("<center><h1>FLUX.1-Dev</h1></center>")
|
82 |
-
|
83 |
-
# Container for all the UI elements
|
84 |
-
with gr.Column(elem_id="app-container"):
|
85 |
-
# Add a text input for the main prompt
|
86 |
-
with gr.Row():
|
87 |
-
with gr.Column(elem_id="prompt-container"):
|
88 |
-
with gr.Row():
|
89 |
-
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
|
90 |
-
|
91 |
-
# Accordion for advanced settings
|
92 |
-
with gr.Row():
|
93 |
-
with gr.Accordion("Advanced Settings", open=False):
|
94 |
-
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
|
95 |
-
with gr.Row():
|
96 |
-
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
|
97 |
-
height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32)
|
98 |
-
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
|
99 |
-
cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
|
100 |
-
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
101 |
-
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1) # Setting the seed to -1 will make it random
|
102 |
-
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
103 |
-
|
104 |
-
# Add a button to trigger the image generation
|
105 |
-
with gr.Row():
|
106 |
-
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
107 |
-
|
108 |
-
# Image output area to display the generated image
|
109 |
-
with gr.Row():
|
110 |
-
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
111 |
-
|
112 |
-
# Bind the button to the query function with the added width and height inputs
|
113 |
-
text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
|
114 |
-
|
115 |
-
# Launch the Gradio app
|
116 |
-
app.launch(show_api=False, share=False)
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
# Define Gradio theme with valid color shortcuts and custom fonts
|
4 |
+
theme = gr.Themes(
|
5 |
+
primary_hue="indigo",
|
6 |
+
secondary_hue="emerald",
|
7 |
+
neutral_hue="gray",
|
8 |
+
font="Rubik" # Assuming 'Rubik' is the correct font setup
|
9 |
+
)
|
10 |
+
|
11 |
+
# Create Gradio blocks with custom CSS for enhanced UI
|
12 |
+
with gr.Blocks(theme=theme, title="RocketGPT - AI-Powered Chatbot") as demo:
|
13 |
+
with gr.TabbedInterface() as tabs:
|
14 |
+
with gr.Blocks() as chat:
|
15 |
+
gr.Markdown("### 💬 SuperChat")
|
16 |
+
gr.HTML("<iframe src='https://Qwen-QwQ-32B-preview.hf.space' width='100%' height='800px' style='border-radius: 8px;'></iframe>")
|
17 |
+
|
18 |
+
with gr.Blocks() as voice:
|
19 |
+
gr.Markdown("### 🎙️ Speech Generator")
|
20 |
+
gr.HTML("<iframe src='https://wifix199-Text-to-speech-LuminaIQ.hf.space' width='100%' height='800px' style='border-radius: 8px;'></iframe>")
|
21 |
+
|
22 |
+
with gr.Blocks() as image:
|
23 |
+
gr.Markdown("### 🖼️ Image Generator")
|
24 |
+
gr.HTML("<iframe src='https://wifix199-Text-to-image-LuminaIQ.hf.space' width='100%' height='800px' style='border-radius: 8px;'></iframe>")
|
25 |
+
|
26 |
+
with gr.Blocks() as video:
|
27 |
+
gr.Markdown("### 📹 Video Engine")
|
28 |
+
gr.HTML("<iframe src=''https://kingnish-instant-video.hf.space' width='100%' height='800px' style='border-radius: 8px;'></iframe>")
|
29 |
+
|
30 |
+
with gr.Blocks() as tryon:
|
31 |
+
gr.Markdown("### 🖼️ Finegrain")
|
32 |
+
gr.HTML("<iframe src=''https://finegrain-finegrain-object-cutter.hf.space' width='100%' height='800px' style='border-radius: 8px;'></iframe>")
|
33 |
+
|
34 |
+
tabs.add_tab(chat, "💬 SuperChat")
|
35 |
+
tabs.add_tab(voice, "🗣️ Speech Generator")
|
36 |
+
tabs.add_tab(image, "🖼️ Image Generator")
|
37 |
+
tabs.add_tab(video, "🎥 Video Generator")
|
38 |
+
tabs.add_tab(tryon, "🖼️Finegrain")
|
39 |
+
|
40 |
+
demo.queue(max_size=300)
|
41 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|