Spaces:
Runtime error
Runtime error
measmonysuon
commited on
Commit
•
b84a77d
1
Parent(s):
70fb798
Update app.py
Browse files
app.py
CHANGED
@@ -21,42 +21,14 @@ DEFAULT_STYLE = "3840 x 2160"
|
|
21 |
logging.basicConfig(level=logging.INFO)
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
result = client_image.predict(
|
31 |
-
prompt=full_prompt,
|
32 |
-
negative_prompt="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
|
33 |
-
use_negative_prompt=True,
|
34 |
-
style=style,
|
35 |
-
seed=0,
|
36 |
-
width=width,
|
37 |
-
height=height,
|
38 |
-
guidance_scale=5,
|
39 |
-
randomize_seed=True,
|
40 |
-
api_name="/run"
|
41 |
-
)
|
42 |
-
logger.info("Image generation successful.")
|
43 |
-
return result
|
44 |
-
except Exception as e:
|
45 |
-
logger.error(f"Error generating image: {e}")
|
46 |
-
return None
|
47 |
-
|
48 |
-
def gradio_interface(prompt, resolution_key):
|
49 |
-
result = generate_image(prompt, resolution_key)
|
50 |
-
|
51 |
-
if result and result[0]:
|
52 |
-
file_path = result[0][0].get('image')
|
53 |
-
if file_path and os.path.exists(file_path):
|
54 |
-
return file_path, "The image was generated successfully."
|
55 |
-
else:
|
56 |
-
return None, "The image file is not available. Please try again later."
|
57 |
-
else:
|
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
|
@@ -80,6 +52,19 @@ def create_gradio_interface(username):
|
|
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),
|
@@ -97,23 +82,13 @@ def create_gradio_interface(username):
|
|
97 |
|
98 |
return interface
|
99 |
|
|
|
100 |
def launch_gradio(username):
|
101 |
interface = create_gradio_interface(username)
|
102 |
interface.launch()
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
return params.get('username', ["Guest"])[0]
|
109 |
-
|
110 |
-
def get_username_from_url(url):
|
111 |
-
# Extract username from the actual URL
|
112 |
-
username = extract_username_from_url(url)
|
113 |
-
logger.info(f"Extracted username: {username}")
|
114 |
-
return username
|
115 |
-
|
116 |
-
# Replace this URL with your actual URL where the Gradio app is hosted
|
117 |
-
url = 'https://measmonysuon-imagen.hf.space/?username=Guest_01' # This should be dynamically obtained if needed
|
118 |
-
username = get_username_from_url(url)
|
119 |
launch_gradio(username)
|
|
|
21 |
logging.basicConfig(level=logging.INFO)
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
24 |
+
# Helper function to extract username from URL
|
25 |
+
def extract_username_from_url(url):
|
26 |
+
parsed_url = urlparse(url)
|
27 |
+
params = parse_qs(parsed_url.query)
|
28 |
+
logger.debug(f"Parsed URL parameters: {params}") # Debugging information
|
29 |
+
return params.get('username', ["Guest"])[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
# Define the Gradio app
|
32 |
def create_gradio_interface(username):
|
33 |
with gr.Blocks() as interface:
|
34 |
# Personalized HTML content
|
|
|
52 |
result_output = gr.Image(label="Generated Image", type="pil")
|
53 |
message_output = gr.Textbox(label="Result", placeholder="Results will be shown here", interactive=False)
|
54 |
|
55 |
+
# Define the function for image generation
|
56 |
+
def gradio_interface(prompt, resolution_key):
|
57 |
+
result = generate_image(prompt, resolution_key)
|
58 |
+
|
59 |
+
if result and result[0]:
|
60 |
+
file_path = result[0][0].get('image')
|
61 |
+
if file_path and os.path.exists(file_path):
|
62 |
+
return file_path, "The image was generated successfully."
|
63 |
+
else:
|
64 |
+
return None, "The image file is not available. Please try again later."
|
65 |
+
else:
|
66 |
+
return None, "There was an error processing your photo. Please try again later."
|
67 |
+
|
68 |
# Set up interaction
|
69 |
generate_button.click(
|
70 |
fn=lambda prompt, resolution_key: gradio_interface(prompt, resolution_key),
|
|
|
82 |
|
83 |
return interface
|
84 |
|
85 |
+
# Launch Gradio app
|
86 |
def launch_gradio(username):
|
87 |
interface = create_gradio_interface(username)
|
88 |
interface.launch()
|
89 |
|
90 |
+
# Example URL (this should be dynamically obtained in your use case)
|
91 |
+
url = 'https://measmonysuon-imagen.hf.space/?username=Guest_001'
|
92 |
+
username = extract_username_from_url(url)
|
93 |
+
logger.info(f"Extracted username: {username}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
launch_gradio(username)
|