|
import os |
|
import gradio as gr |
|
import requests |
|
|
|
|
|
BASE_URL = os.getenv("BASE_URL") |
|
API_KEY = os.getenv("API_KEY") |
|
|
|
|
|
def generate_image(prompt, negative_prompt, sampling_steps, cfg_scale, seed): |
|
headers = {"Authorization": f"Bearer {API_KEY}"} |
|
|
|
|
|
params = { |
|
"prompt": prompt, |
|
"negative_prompt": negative_prompt, |
|
"sampling_steps": int(sampling_steps), |
|
"cfg_scale": int(cfg_scale), |
|
"seed": int(seed) |
|
} |
|
|
|
|
|
response = requests.post(BASE_URL, headers=headers, json=params) |
|
|
|
|
|
generated_image = response.content |
|
|
|
return generated_image |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_image, |
|
inputs=[ |
|
gr.Textbox(default="Prompt"), |
|
gr.Textbox(default="Negative Prompt"), |
|
], |
|
outputs=gr.Image(type="pil"), |
|
live=True, |
|
layout="vertical", |
|
title="Hugging Face Image Generator", |
|
description="Generate images using Hugging Face Inference API.", |
|
theme="compact", |
|
tabs=[ |
|
"Prompt Input", |
|
[ |
|
gr.Slider(minimum=1, maximum=30, step=1, default=15, label="Sampling Steps"), |
|
gr.Slider(minimum=1, maximum=20, step=1, default=10, label="CFG Scale"), |
|
gr.Textbox(default="-1", label="Seed"), |
|
] |
|
], |
|
interpretation="default" |
|
) |
|
|
|
|
|
iface.launch() |
|
|