Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,41 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import base64
|
4 |
+
from io import BytesIO
|
5 |
+
import os
|
6 |
|
7 |
+
API_URL = "https://api-inference.huggingface.co/models/soiz1/shirakami-hubuki-diffusion"
|
8 |
+
HEADERS = {"Authorization": f"Bearer {os.getenv('token')}"}
|
9 |
+
|
10 |
+
def generate_image(prompt, negative_prompt, steps, guidance_scale):
|
11 |
+
payload = {
|
12 |
+
"inputs": prompt,
|
13 |
+
"parameters": {
|
14 |
+
"negative_prompt": negative_prompt,
|
15 |
+
"num_inference_steps": steps,
|
16 |
+
"guidance_scale": guidance_scale
|
17 |
+
}
|
18 |
+
}
|
19 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
20 |
+
if response.status_code == 200:
|
21 |
+
image_data = response.content
|
22 |
+
image = BytesIO(image_data)
|
23 |
+
return image
|
24 |
+
else:
|
25 |
+
return f"Error: {response.status_code}, {response.text}"
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("# Shirakami Hubuki LoRA Image Generator")
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column():
|
31 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Describe your image")
|
32 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What to avoid")
|
33 |
+
steps = gr.Slider(1, 50, value=25, step=1, label="Inference Steps")
|
34 |
+
guidance_scale = gr.Slider(1, 20, value=7.5, step=0.1, label="Guidance Scale")
|
35 |
+
submit = gr.Button("Generate")
|
36 |
+
with gr.Column():
|
37 |
+
output_image = gr.Image(label="Generated Image")
|
38 |
+
|
39 |
+
submit.click(generate_image, inputs=[prompt, negative_prompt, steps, guidance_scale], outputs=output_image)
|
40 |
+
|
41 |
+
demo.launch()
|