Spaces:
Runtime error
Runtime error
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() |