Spaces:
Runtime error
Runtime error
File size: 1,536 Bytes
e8bac0f ff1697a e8bac0f 04e9db1 e8bac0f 04e9db1 8b62ce7 ff1697a e8bac0f ff1697a 263e495 ff1697a 8b62ce7 c97f523 ff1697a c97f523 263e495 8b62ce7 ff1697a a6549b1 ff1697a a5a2931 ff1697a a6549b1 83746e4 a5a2931 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
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."
# 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"
)
if __name__ == "__main__":
demo.launch()
|