soiz1's picture
Update app.py
0742b23 verified
import gradio as gr
import requests
import io
import os
import json
import random
from PIL import Image
def query(model_name, prompt, is_negative, steps, cfg_scale, seed, strength, width, height):
API_URL = f"https://api-inference.huggingface.co/models/{model_name}"
headers = {"Authorization": f"Bearer {os.getenv('token')}"}
payload = {
"inputs": prompt,
"is_negative": is_negative,
"steps": steps,
"cfg_scale": cfg_scale,
"seed": seed if seed != -1 else random.randint(1, 1000000000),
"strength": strength,
"parameters": {
"width": width,
"height": height
}
}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code != 200:
return f"Error {response.status_code}: {response.text}"
try:
image = Image.open(io.BytesIO(response.content))
return image
except Exception:
return f"Invalid response: {response.text}"
demo = gr.Interface(
fn=query,
inputs=[
gr.Textbox(value="strangerzonehf/Flux-Animeo-v1-LoRA", label="ใƒขใƒ‡ใƒซๅ"),
gr.Textbox(label="ใƒ—ใƒญใƒณใƒ—ใƒˆ", placeholder="็”Ÿๆˆใ™ใ‚‹็”ปๅƒใฎ่ชฌๆ˜Žใ‚’ๅ…ฅๅŠ›"),
gr.Checkbox(label="ใƒใ‚ฌใƒ†ใ‚ฃใƒ–ใƒ—ใƒญใƒณใƒ—ใƒˆใ‚’ไฝฟ็”จ"),
gr.Slider(1, 100, step=1, value=25, label="ใ‚นใƒ†ใƒƒใƒ—ๆ•ฐ"),
gr.Slider(1, 20, step=0.5, value=7, label="CFGใ‚นใ‚ฑใƒผใƒซ"),
gr.Number(-1, label="ใ‚ทใƒผใƒ‰ (-1ใงใƒฉใƒณใƒ€ใƒ )"),
gr.Slider(0.0, 1.0, step=0.1, value=0.7, label="ๅค‰ๆ›ๅผทๅบฆ"),
gr.Slider(256, 1024, step=64, value=512, label="ๅน…"),
gr.Slider(256, 1024, step=64, value=512, label="้ซ˜ใ•")
],
outputs=gr.Image(label="็”Ÿๆˆ็”ปๅƒ"),
title="Flux-Animeo ็”ปๅƒ็”Ÿๆˆ",
description="ใƒ†ใ‚ญใ‚นใƒˆใƒ—ใƒญใƒณใƒ—ใƒˆใจใ‚ชใƒ—ใ‚ทใƒงใƒณใ‚’่จญๅฎšใ—ใฆ็”ปๅƒใ‚’็”Ÿๆˆใ—ใพใ™ใ€‚"
)
demo.launch()