ofai-it2v2 / app.py
fantaxy's picture
Update app.py
b8e1aa4 verified
raw
history blame
No virus
1.6 kB
import gradio as gr
from gradio_client import Client
import os
import logging
# ๋กœ๊น… ์„ค์ •
logging.basicConfig(level=logging.INFO)
# API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
api_client = Client("http://211.233.58.202:7960/")
def respond(message):
logging.info("Received message: %s", message)
try:
# ์ด๋ฏธ์ง€ ์ƒ์„ฑ ์š”์ฒญ
result = api_client.predict(
prompt=message,
seed=123,
randomize_seed=False,
width=1024,
height=576,
guidance_scale=5,
num_inference_steps=28,
api_name="/infer_t2i"
)
logging.info("API response received: %s", result)
# ๊ฒฐ๊ณผ ํ™•์ธ ๋ฐ ์ฒ˜๋ฆฌ
if isinstance(result, dict) and 'url' in result:
return result['url']
elif isinstance(result, tuple):
logging.error("Unexpected tuple response: %s", result)
# ํŠœํ”Œ ์‘๋‹ต ์ฒ˜๋ฆฌ, ์˜ˆ๋ฅผ ๋“ค์–ด result[0] ์ด url์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๊ฐ€์ •
return result[0]
else:
raise ValueError("Unexpected API response format")
except Exception as e:
logging.error("Error during API request: %s", str(e))
return "Failed to generate image due to an error."
css = """
footer {
visibility: hidden;
}
"""
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
demo = gr.Interface(
fn=respond,
inputs=gr.Textbox(label="Enter your prompt for image generation"),
outputs=gr.Image(label="Generated Image"),
theme="Nymbo/Nymbo_Theme",
css=css
)
if __name__ == "__main__":
demo.launch()