Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,9 @@ logging.basicConfig(level=logging.INFO)
|
|
| 10 |
api_client = Client("http://211.233.58.202:7960/")
|
| 11 |
|
| 12 |
def respond(message):
|
|
|
|
|
|
|
|
|
|
| 13 |
logging.info("Received message: %s", message)
|
| 14 |
|
| 15 |
try:
|
|
@@ -28,15 +31,15 @@ def respond(message):
|
|
| 28 |
|
| 29 |
# 결과 확인 및 처리
|
| 30 |
if isinstance(result, dict) and 'url' in result:
|
| 31 |
-
return result['url']
|
| 32 |
elif isinstance(result, tuple):
|
| 33 |
logging.error("Unexpected tuple response: %s", result)
|
| 34 |
-
return result[0]
|
| 35 |
else:
|
| 36 |
raise ValueError("Unexpected API response format")
|
| 37 |
except Exception as e:
|
| 38 |
logging.error("Error during API request: %s", str(e))
|
| 39 |
-
return "Failed to generate image due to an error."
|
| 40 |
|
| 41 |
css = """
|
| 42 |
footer {
|
|
@@ -67,16 +70,17 @@ examples = [
|
|
| 67 |
["A fantasy map of a fictional world, with detailed terrain and cities.", "q19.webp"]
|
| 68 |
]
|
| 69 |
|
| 70 |
-
# Gradio 인터페이스 설정
|
| 71 |
demo = gr.Interface(
|
| 72 |
fn=respond,
|
| 73 |
inputs=gr.Textbox(label="Enter your prompt for image generation"),
|
| 74 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 75 |
examples=examples,
|
| 76 |
theme="Nymbo/Nymbo_Theme",
|
| 77 |
css=css,
|
| 78 |
-
|
| 79 |
-
|
| 80 |
)
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|
|
|
|
| 10 |
api_client = Client("http://211.233.58.202:7960/")
|
| 11 |
|
| 12 |
def respond(message):
|
| 13 |
+
if message.endswith(('.png', '.jpg', '.jpeg', '.webp')):
|
| 14 |
+
return message, message # 프롬프트와 이미지 파일명 반환
|
| 15 |
+
|
| 16 |
logging.info("Received message: %s", message)
|
| 17 |
|
| 18 |
try:
|
|
|
|
| 31 |
|
| 32 |
# 결과 확인 및 처리
|
| 33 |
if isinstance(result, dict) and 'url' in result:
|
| 34 |
+
return message, result['url']
|
| 35 |
elif isinstance(result, tuple):
|
| 36 |
logging.error("Unexpected tuple response: %s", result)
|
| 37 |
+
return message, result[0]
|
| 38 |
else:
|
| 39 |
raise ValueError("Unexpected API response format")
|
| 40 |
except Exception as e:
|
| 41 |
logging.error("Error during API request: %s", str(e))
|
| 42 |
+
return message, "Failed to generate image due to an error."
|
| 43 |
|
| 44 |
css = """
|
| 45 |
footer {
|
|
|
|
| 70 |
["A fantasy map of a fictional world, with detailed terrain and cities.", "q19.webp"]
|
| 71 |
]
|
| 72 |
|
|
|
|
| 73 |
demo = gr.Interface(
|
| 74 |
fn=respond,
|
| 75 |
inputs=gr.Textbox(label="Enter your prompt for image generation"),
|
| 76 |
+
outputs=[
|
| 77 |
+
gr.Textbox(label="Prompt"),
|
| 78 |
+
gr.Image(label="Generated Image")
|
| 79 |
+
],
|
| 80 |
examples=examples,
|
| 81 |
theme="Nymbo/Nymbo_Theme",
|
| 82 |
css=css,
|
| 83 |
+
cache_examples=False # 예제 캐싱 비활성화
|
|
|
|
| 84 |
)
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|