Spaces:
Runtime error
Runtime error
Commit
•
dca1c6a
1
Parent(s):
2639d84
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
api_url = "https://5cb20b40-572c-426f-9466-995256f9b6eb.id.repl.co/generate_image"
|
5 |
+
|
6 |
+
def generate_image(prompt, seed=0, negative_prompt="", model="Deliberate", sampler="k_dpmpp_2s_a", steps=50):
|
7 |
+
data = {
|
8 |
+
"prompt": prompt,
|
9 |
+
"seed": seed,
|
10 |
+
"negative_prompt": negative_prompt,
|
11 |
+
"model": model,
|
12 |
+
"sampler": sampler,
|
13 |
+
"steps": steps
|
14 |
+
}
|
15 |
+
response = requests.post(api_url, data=data)
|
16 |
+
if response.status_code == 200:
|
17 |
+
return response.json()["url"]
|
18 |
+
else:
|
19 |
+
return None
|
20 |
+
|
21 |
+
inputs = [
|
22 |
+
gr.inputs.Textbox(label="Prompt"),
|
23 |
+
gr.inputs.Number(label="Seed", default=0),
|
24 |
+
gr.inputs.Textbox(label="Negative Prompt", default=""),
|
25 |
+
gr.inputs.Dropdown(["Deliberate", "Curie", "BigGAN"], label="Model", default="Deliberate"),
|
26 |
+
gr.inputs.Dropdown(["k_dpmpp_2s_a", "k_heun", "k_dpps_2s_a"], label="Sampler", default="k_dpmpp_2s_a"),
|
27 |
+
gr.inputs.Number(label="Steps", default=50)
|
28 |
+
]
|
29 |
+
|
30 |
+
outputs = gr.outputs.Image(label="Generated Image")
|
31 |
+
|
32 |
+
interface = gr.Interface(generate_image, inputs, outputs, title="Generate Images from Prompts",
|
33 |
+
description="Enter a prompt and generate an image using this API.",
|
34 |
+
examples=[["A cat sitting on a chair"],
|
35 |
+
["A landscape with mountains and a lake"],
|
36 |
+
["A portrait of a woman with red hair"]])
|
37 |
+
|
38 |
+
interface.launch()
|