measmonysuon commited on
Commit
2abf6c4
1 Parent(s): 0d23f2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -6,6 +6,7 @@ import requests
6
  from huggingface_hub import login, whoami, HfFolder, HfApi, SpaceHardware
7
  import time
8
  import torch
 
9
 
10
  webhook_server = os.getenv('webhook_server')
11
  API_TOKEN = os.getenv('ZeroGPU')
@@ -69,7 +70,18 @@ def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
69
  except Exception as e:
70
  logger.error(f"Error generating image: {e}")
71
  return None
72
-
 
 
 
 
 
 
 
 
 
 
 
73
  def gradio_interface(prompt, resolution_key, user_chat_id):
74
  if not user_chat_id.strip():
75
  return None, "User Chat ID cannot be blank. Please provide a valid User Chat ID or register with @supportBot to get UID."
@@ -94,11 +106,14 @@ def gradio_interface(prompt, resolution_key, user_chat_id):
94
  full_file_url = base_url + file_path
95
 
96
  if os.path.exists(file_path):
 
 
 
97
  # Update user points and notify webhook
98
  update_user_points(user_chat_id, -5)
99
- notify_webhook_with_file(user_chat_id, full_file_url, gpu_info) # Notify webhook with full file URL
100
 
101
- return full_file_url, f"Check your telegram, The image was generated successfully. GPU Info: {json.dumps(gpu_info)}"
102
 
103
  return None, "The image file is not available. Please try again later."
104
 
@@ -130,9 +145,9 @@ def handle_generate_image(prompt, resolution_key, user_chat_id):
130
  if points >= 5:
131
  result = gradio_interface(prompt, resolution_key, user_chat_id)
132
  if result[0]:
133
- # Include the GPU info in the success message
134
- full_file_url, gpu_info = result
135
- return full_file_url, f"Check your telegram, The image was generated successfully. GPU Info: {json.dumps(gpu_info)}"
136
 
137
  return None, "There was an error processing your photo. Please try again later."
138
 
 
6
  from huggingface_hub import login, whoami, HfFolder, HfApi, SpaceHardware
7
  import time
8
  import torch
9
+ import json
10
 
11
  webhook_server = os.getenv('webhook_server')
12
  API_TOKEN = os.getenv('ZeroGPU')
 
70
  except Exception as e:
71
  logger.error(f"Error generating image: {e}")
72
  return None
73
+
74
+ def format_gpu_info(gpu_info):
75
+ # Extract and format GPU information
76
+ is_cuda_available = gpu_info.get('is_cuda_available', False)
77
+ device_name = gpu_info.get('device_name', 'Unknown Device')
78
+
79
+ # Create a friendly message
80
+ cuda_status = "Available" if is_cuda_available else "Not Available"
81
+ formatted_info = f"Device: {device_name}, CUDA: {cuda_status}"
82
+
83
+ return formatted_info
84
+
85
  def gradio_interface(prompt, resolution_key, user_chat_id):
86
  if not user_chat_id.strip():
87
  return None, "User Chat ID cannot be blank. Please provide a valid User Chat ID or register with @supportBot to get UID."
 
106
  full_file_url = base_url + file_path
107
 
108
  if os.path.exists(file_path):
109
+ # Format GPU info
110
+ formatted_gpu_info = format_gpu_info(gpu_info)
111
+
112
  # Update user points and notify webhook
113
  update_user_points(user_chat_id, -5)
114
+ notify_webhook_with_file(user_chat_id, full_file_url, formatted_gpu_info) # Notify webhook with full file URL
115
 
116
+ return full_file_url, f"Check your telegram, The image was generated successfully. GPU Info: {formatted_gpu_info}"
117
 
118
  return None, "The image file is not available. Please try again later."
119
 
 
145
  if points >= 5:
146
  result = gradio_interface(prompt, resolution_key, user_chat_id)
147
  if result[0]:
148
+ # Include the formatted GPU info in the success message
149
+ full_file_url, gpu_info_message = result
150
+ return full_file_url, f"Image generated and sent successfully to telegram. By {gpu_info_message}"
151
 
152
  return None, "There was an error processing your photo. Please try again later."
153