Spaces:
Runtime error
Runtime error
measmonysuon
commited on
Commit
•
a90d186
1
Parent(s):
f42d0d7
Update app.py
Browse files
app.py
CHANGED
@@ -124,9 +124,9 @@ def notify_webhook(user_chat_id):
|
|
124 |
except requests.RequestException as e:
|
125 |
logger.error(f"Error sending webhook notification: {e}")
|
126 |
|
127 |
-
def notify_webhook_with_file(user_chat_id,
|
128 |
webhook_url = f"{webhook_server}/notify_image"
|
129 |
-
payload = {'user_chat_id': user_chat_id, 'file_path':
|
130 |
try:
|
131 |
response = requests.post(webhook_url, json=payload)
|
132 |
response.raise_for_status()
|
@@ -154,15 +154,18 @@ def gradio_interface(prompt, resolution_key, user_chat_id):
|
|
154 |
|
155 |
result = generate_image(prompt, resolution_key)
|
156 |
if result and result[0]:
|
157 |
-
|
158 |
-
if
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
163 |
return None, "There was an error processing your photo. Please try again later."
|
164 |
-
|
165 |
-
|
166 |
|
167 |
def handle_generate_image(prompt, resolution_key, user_chat_id):
|
168 |
points = get_user_points(user_chat_id)
|
|
|
124 |
except requests.RequestException as e:
|
125 |
logger.error(f"Error sending webhook notification: {e}")
|
126 |
|
127 |
+
def notify_webhook_with_file(user_chat_id, full_file_url):
|
128 |
webhook_url = f"{webhook_server}/notify_image"
|
129 |
+
payload = {'user_chat_id': user_chat_id, 'file_path': full_file_url}
|
130 |
try:
|
131 |
response = requests.post(webhook_url, json=payload)
|
132 |
response.raise_for_status()
|
|
|
154 |
|
155 |
result = generate_image(prompt, resolution_key)
|
156 |
if result and result[0]:
|
157 |
+
file_path = result[0][0].get('image')
|
158 |
+
if file_path:
|
159 |
+
# Combine base URL with file path to create full URL
|
160 |
+
base_url = "https://mukaist-dalle-4k.hf.space/file="
|
161 |
+
full_file_url = base_url + file_path
|
162 |
+
|
163 |
+
if os.path.exists(file_path):
|
164 |
+
update_user_points(user_chat_id, -5)
|
165 |
+
notify_webhook_with_file(user_chat_id, full_file_url) # Notify webhook with full file URL
|
166 |
+
return full_file_url, "The image was generated successfully."
|
167 |
+
return None, "The image file is not available. Please try again later."
|
168 |
return None, "There was an error processing your photo. Please try again later."
|
|
|
|
|
169 |
|
170 |
def handle_generate_image(prompt, resolution_key, user_chat_id):
|
171 |
points = get_user_points(user_chat_id)
|