Spaces:
Runtime error
Runtime error
measmonysuon
commited on
Commit
•
8e64f0d
1
Parent(s):
9a29b5b
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,20 @@ import os
|
|
4 |
import logging
|
5 |
from urllib.parse import parse_qs, urlparse
|
6 |
|
|
|
7 |
client_image = Client("mukaist/DALLE-4K")
|
|
|
|
|
8 |
resolutions = {
|
9 |
"896x1152": (896, 1152),
|
10 |
"1024x1024": (1024, 1024),
|
11 |
"1216x832": (1216, 832)
|
12 |
}
|
|
|
|
|
13 |
DEFAULT_STYLE = "3840 x 2160"
|
|
|
|
|
14 |
logging.basicConfig(level=logging.INFO)
|
15 |
logger = logging.getLogger(__name__)
|
16 |
|
@@ -18,6 +25,7 @@ def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
|
|
18 |
resolution = resolutions.get(resolution_key, (1024, 1024))
|
19 |
width, height = resolution
|
20 |
full_prompt = f"{prompt}, Canon EOS R5, 4K, Photo-Realistic, appearing photorealistic with super fine details, high resolution, natural look, hyper realistic photography, cinematic lighting, --ar 64:37, --v 6.0, --style raw, --stylize 750"
|
|
|
21 |
try:
|
22 |
result = client_image.predict(
|
23 |
prompt=full_prompt,
|
@@ -50,19 +58,8 @@ def gradio_interface(prompt, resolution_key):
|
|
50 |
return None, "There was an error processing your photo. Please try again later."
|
51 |
|
52 |
def create_gradio_interface(username):
|
53 |
-
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
54 |
-
resolution_dropdown = gr.Dropdown(choices=list(resolutions.keys()), label="Resolution", value="1024x1024")
|
55 |
-
generate_button = gr.Button("Generate")
|
56 |
-
|
57 |
-
result_output = gr.Image(label="Generated Image", type="pil")
|
58 |
-
message_output = gr.Textbox(label="Result", placeholder="Results will be shown here", interactive=False)
|
59 |
-
|
60 |
-
generate_button.click(fn=lambda prompt, resolution_key: gradio_interface(prompt, resolution_key),
|
61 |
-
inputs=[prompt_input, resolution_dropdown],
|
62 |
-
outputs=[result_output, message_output])
|
63 |
-
|
64 |
-
|
65 |
with gr.Blocks() as interface:
|
|
|
66 |
gr.HTML(f"""
|
67 |
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
68 |
<script>
|
@@ -73,7 +70,22 @@ def create_gradio_interface(username):
|
|
73 |
</script>
|
74 |
<h3>Welcome, {username}! Generate images based on prompts.</h3>
|
75 |
""")
|
|
|
|
|
|
|
|
|
|
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
gr.HTML("""
|
79 |
<style>
|
@@ -82,7 +94,7 @@ def create_gradio_interface(username):
|
|
82 |
}
|
83 |
</style>
|
84 |
""")
|
85 |
-
|
86 |
return interface
|
87 |
|
88 |
def launch_gradio(username):
|
@@ -101,5 +113,6 @@ def get_username_from_url():
|
|
101 |
logger.info(f"Extracted username: {username}")
|
102 |
return username
|
103 |
|
|
|
104 |
username = get_username_from_url()
|
105 |
launch_gradio(username)
|
|
|
4 |
import logging
|
5 |
from urllib.parse import parse_qs, urlparse
|
6 |
|
7 |
+
# Initialize the client for image generation
|
8 |
client_image = Client("mukaist/DALLE-4K")
|
9 |
+
|
10 |
+
# Define resolutions
|
11 |
resolutions = {
|
12 |
"896x1152": (896, 1152),
|
13 |
"1024x1024": (1024, 1024),
|
14 |
"1216x832": (1216, 832)
|
15 |
}
|
16 |
+
|
17 |
+
# Define the default style
|
18 |
DEFAULT_STYLE = "3840 x 2160"
|
19 |
+
|
20 |
+
# Set up logging
|
21 |
logging.basicConfig(level=logging.INFO)
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
|
|
25 |
resolution = resolutions.get(resolution_key, (1024, 1024))
|
26 |
width, height = resolution
|
27 |
full_prompt = f"{prompt}, Canon EOS R5, 4K, Photo-Realistic, appearing photorealistic with super fine details, high resolution, natural look, hyper realistic photography, cinematic lighting, --ar 64:37, --v 6.0, --style raw, --stylize 750"
|
28 |
+
|
29 |
try:
|
30 |
result = client_image.predict(
|
31 |
prompt=full_prompt,
|
|
|
58 |
return None, "There was an error processing your photo. Please try again later."
|
59 |
|
60 |
def create_gradio_interface(username):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
with gr.Blocks() as interface:
|
62 |
+
# Personalized HTML content
|
63 |
gr.HTML(f"""
|
64 |
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
65 |
<script>
|
|
|
70 |
</script>
|
71 |
<h3>Welcome, {username}! Generate images based on prompts.</h3>
|
72 |
""")
|
73 |
+
|
74 |
+
# Create input components
|
75 |
+
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
76 |
+
resolution_dropdown = gr.Dropdown(choices=list(resolutions.keys()), label="Resolution", value="1024x1024")
|
77 |
+
generate_button = gr.Button("Generate")
|
78 |
|
79 |
+
# Create output components
|
80 |
+
result_output = gr.Image(label="Generated Image", type="pil")
|
81 |
+
message_output = gr.Textbox(label="Result", placeholder="Results will be shown here", interactive=False)
|
82 |
+
|
83 |
+
# Set up interaction
|
84 |
+
generate_button.click(
|
85 |
+
fn=lambda prompt, resolution_key: gradio_interface(prompt, resolution_key),
|
86 |
+
inputs=[prompt_input, resolution_dropdown],
|
87 |
+
outputs=[result_output, message_output]
|
88 |
+
)
|
89 |
|
90 |
gr.HTML("""
|
91 |
<style>
|
|
|
94 |
}
|
95 |
</style>
|
96 |
""")
|
97 |
+
|
98 |
return interface
|
99 |
|
100 |
def launch_gradio(username):
|
|
|
113 |
logger.info(f"Extracted username: {username}")
|
114 |
return username
|
115 |
|
116 |
+
# Launch Gradio with the extracted or default username
|
117 |
username = get_username_from_url()
|
118 |
launch_gradio(username)
|