Spaces:
Runtime error
Runtime error
measmonysuon
commited on
Commit
•
374f848
1
Parent(s):
1d2163e
Update app.py
Browse files
app.py
CHANGED
@@ -101,12 +101,17 @@ def extract_user_chat_id_from_url(url):
|
|
101 |
return params.get('user_chat_id', ["Guest"])[0]
|
102 |
|
103 |
def gradio_interface(prompt, resolution_key, user_chat_id):
|
|
|
|
|
|
|
|
|
|
|
104 |
result = generate_image(prompt, resolution_key)
|
105 |
|
106 |
if result and result[0]:
|
107 |
file_path = result[0][0].get('image')
|
108 |
if file_path and os.path.exists(file_path):
|
109 |
-
update_user_points(user_chat_id, -5) # Deduct
|
110 |
return file_path, "The image was generated successfully."
|
111 |
else:
|
112 |
return None, "The image file is not available. Please try again later."
|
@@ -142,7 +147,7 @@ def create_gradio_interface():
|
|
142 |
user_chat_id_input = gr.Textbox(
|
143 |
label="Your UID",
|
144 |
placeholder="Your UID",
|
145 |
-
|
146 |
)
|
147 |
points_output = gr.Textbox(label="Your Balances", placeholder="Your Points")
|
148 |
|
|
|
101 |
return params.get('user_chat_id', ["Guest"])[0]
|
102 |
|
103 |
def gradio_interface(prompt, resolution_key, user_chat_id):
|
104 |
+
# Check if user_chat_id is empty
|
105 |
+
if not user_chat_id.strip():
|
106 |
+
return None, "User Chat ID cannot be blank. Please provide a valid User Chat ID."
|
107 |
+
|
108 |
+
# Proceed with image generation if user_chat_id is provided
|
109 |
result = generate_image(prompt, resolution_key)
|
110 |
|
111 |
if result and result[0]:
|
112 |
file_path = result[0][0].get('image')
|
113 |
if file_path and os.path.exists(file_path):
|
114 |
+
update_user_points(user_chat_id, -5) # Deduct points for each image generated
|
115 |
return file_path, "The image was generated successfully."
|
116 |
else:
|
117 |
return None, "The image file is not available. Please try again later."
|
|
|
147 |
user_chat_id_input = gr.Textbox(
|
148 |
label="Your UID",
|
149 |
placeholder="Your UID",
|
150 |
+
interactive=True # Make this non-editable
|
151 |
)
|
152 |
points_output = gr.Textbox(label="Your Balances", placeholder="Your Points")
|
153 |
|