Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,38 @@
|
|
| 1 |
-
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
)
|
| 12 |
-
pipe = pipe.to(device)
|
| 13 |
-
|
| 14 |
-
styles = {
|
| 15 |
-
"Realistic": "highly detailed, realistic, 4k",
|
| 16 |
-
"Cartoon": "cartoon style, colorful",
|
| 17 |
-
"Anime": "anime style",
|
| 18 |
-
"Sketch": "pencil sketch"
|
| 19 |
}
|
| 20 |
|
| 21 |
-
def generate_image(prompt
|
| 22 |
if not prompt.strip():
|
| 23 |
-
return None, "
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
num_inference_steps=int(steps),
|
| 31 |
-
guidance_scale=float(guidance),
|
| 32 |
-
generator=generator
|
| 33 |
-
).images[0]
|
| 34 |
|
| 35 |
-
return
|
| 36 |
|
| 37 |
with gr.Blocks() as app:
|
| 38 |
-
gr.Markdown("#
|
| 39 |
-
gr.Markdown("Powered by Stable Diffusion")
|
| 40 |
|
| 41 |
prompt = gr.Textbox(label="Prompt")
|
| 42 |
-
style = gr.Dropdown(["Realistic", "Cartoon", "Anime", "Sketch"], value="Realistic")
|
| 43 |
-
|
| 44 |
-
steps = gr.Slider(10, 50, value=25)
|
| 45 |
-
guidance = gr.Slider(5.0, 15.0, value=7.5)
|
| 46 |
-
seed = gr.Number(value=0)
|
| 47 |
-
|
| 48 |
btn = gr.Button("Generate")
|
| 49 |
|
| 50 |
-
|
| 51 |
status = gr.Textbox()
|
| 52 |
|
| 53 |
-
btn.click(generate_image,
|
| 54 |
|
| 55 |
app.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
HF_TOKEN = "images"
|
| 5 |
+
|
| 6 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
| 7 |
+
|
| 8 |
+
headers = {
|
| 9 |
+
"Authorization": f"Bearer {HF_TOKEN}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
+
def generate_image(prompt):
|
| 13 |
if not prompt.strip():
|
| 14 |
+
return None, "Enter prompt"
|
| 15 |
|
| 16 |
+
response = requests.post(
|
| 17 |
+
API_URL,
|
| 18 |
+
headers=headers,
|
| 19 |
+
json={"inputs": prompt}
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
if response.status_code != 200:
|
| 23 |
+
return None, response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
return response.content, "Done"
|
| 26 |
|
| 27 |
with gr.Blocks() as app:
|
| 28 |
+
gr.Markdown("# Text to Image AI")
|
|
|
|
| 29 |
|
| 30 |
prompt = gr.Textbox(label="Prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
btn = gr.Button("Generate")
|
| 32 |
|
| 33 |
+
img = gr.Image(type="pil")
|
| 34 |
status = gr.Textbox()
|
| 35 |
|
| 36 |
+
btn.click(generate_image, prompt, [img, status])
|
| 37 |
|
| 38 |
app.launch()
|