|
import gradio as gr |
|
from gradio_client import Client |
|
import os |
|
import logging |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
|
|
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) |
|
|
|
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; |
|
} |
|
""" |
|
|
|
|
|
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() |
|
|