File size: 2,219 Bytes
e8bac0f
ff1697a
e8bac0f
04e9db1
e8bac0f
04e9db1
 
8b62ce7
ff1697a
 
e8bac0f
ff1697a
 
 
263e495
ff1697a
 
8b62ce7
 
 
 
 
 
 
 
 
c97f523
ff1697a
c97f523
 
 
 
 
 
 
 
263e495
8b62ce7
ff1697a
a6549b1
b8e1aa4
 
 
 
 
 
5843541
 
 
 
 
 
 
 
 
 
 
 
 
 
ff1697a
 
a5a2931
ff1697a
 
5843541
b8e1aa4
 
a6549b1
83746e4
 
5843541
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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)
            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;
}
"""

# ์ด๋ฏธ์ง€ ์ƒ์„ฑ์„ ์œ„ํ•œ ์˜ˆ์ œ ํ”„๋กฌํ”„ํŠธ
examples = [
    ["A futuristic cityscape at sunset."],
    ["A portrait of a cat wearing a monocle."],
    ["A serene landscape with mountains in the background and a clear lake in the foreground."],
    ["A street scene from Tokyo at night, vibrant and full of lights."],
    ["An astronaut riding a horse on Mars."],
    ["A surreal painting of a tree growing books."],
    ["A cottage in a snowy forest, lit by warm lights."],
    ["A still life of various fruits and a wine glass on a table."],
    ["A digital artwork of a neon-lit alley in a cyberpunk city."],
    ["A fantasy map of a fictional world, with detailed terrain and cities."]
]

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
demo = gr.Interface(
    fn=respond,
    inputs=gr.Textbox(label="Enter your prompt for image generation"),
    outputs=gr.Image(label="Generated Image"),
    examples=examples,
    theme="Nymbo/Nymbo_Theme",
    css=css
)

if __name__ == "__main__":
    demo.launch()