sahadev10 commited on
Commit
66cfcee
Β·
verified Β·
1 Parent(s): f585f99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -37
app.py CHANGED
@@ -138,63 +138,63 @@ with open("blazer_model.pkl", "rb") as f:
138
  clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").eval().cpu()
139
  clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
140
 
141
- # def send_to_backend(img_path, user_id):
142
- # if not user_id:
143
- # return "❌ user_id not found in URL."
144
-
145
- # if not img_path or not os.path.exists(img_path):
146
- # return "⚠️ No image selected or image not found."
147
-
148
- # try:
149
- # with open(img_path, 'rb') as f:
150
- # files = {'file': ('generated_image.png', f, 'image/png')}
151
-
152
- # # Your backend endpoint here
153
- # url = f"https://e335-103-40-74-83.ngrok-free.app/images/upload/{user_id}"
154
- # response = requests.post(url, files=files)
155
-
156
- # if response.status_code == 201:
157
- # return "βœ… Image uploaded and saved to database!"
158
- # else:
159
- # console.log({response.text})
160
- # return f"❌ Upload failed: {response.status_code} - {response.text}"
161
-
162
- # except Exception as e:
163
- # return f"⚠️ Error: {str(e)}"
164
-
165
-
166
- import os
167
- import requests # Make sure you import this!
168
-
169
  def send_to_backend(img_path, user_id):
170
- print(f"πŸ’‘ [DEBUG] Sending image to backend | img_path={img_path}, user_id={user_id}")
171
-
172
  if not user_id:
173
- print("❌ [DEBUG] Missing user_id in URL.")
174
  return "❌ user_id not found in URL."
175
 
176
  if not img_path or not os.path.exists(img_path):
177
- print("⚠️ [DEBUG] Image path invalid or does not exist.")
178
  return "⚠️ No image selected or image not found."
179
 
180
  try:
181
  with open(img_path, 'rb') as f:
182
  files = {'file': ('generated_image.png', f, 'image/png')}
 
 
183
  url = f"https://e335-103-40-74-83.ngrok-free.app/images/upload/{user_id}"
184
- print(f"πŸ” [DEBUG] Sending POST to {url}")
185
  response = requests.post(url, files=files)
186
-
187
- print(f"πŸ“© [DEBUG] Response: {response.status_code} - {response.text}")
188
- if response.status_code == 201 or response.status_code == 200:
189
  return "βœ… Image uploaded and saved to database!"
190
  else:
 
191
  return f"❌ Upload failed: {response.status_code} - {response.text}"
192
 
193
  except Exception as e:
194
- print(f"⚠️ [ERROR] Exception during upload: {str(e)}")
195
  return f"⚠️ Error: {str(e)}"
196
 
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
 
200
 
 
138
  clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").eval().cpu()
139
  clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  def send_to_backend(img_path, user_id):
 
 
142
  if not user_id:
 
143
  return "❌ user_id not found in URL."
144
 
145
  if not img_path or not os.path.exists(img_path):
 
146
  return "⚠️ No image selected or image not found."
147
 
148
  try:
149
  with open(img_path, 'rb') as f:
150
  files = {'file': ('generated_image.png', f, 'image/png')}
151
+
152
+ # Your backend endpoint here
153
  url = f"https://e335-103-40-74-83.ngrok-free.app/images/upload/{user_id}"
 
154
  response = requests.post(url, files=files)
155
+
156
+ if response.status_code == 201:
 
157
  return "βœ… Image uploaded and saved to database!"
158
  else:
159
+ console.log({response.text})
160
  return f"❌ Upload failed: {response.status_code} - {response.text}"
161
 
162
  except Exception as e:
 
163
  return f"⚠️ Error: {str(e)}"
164
 
165
 
166
+ # import os
167
+ # import requests # Make sure you import this!
168
+
169
+ # def send_to_backend(img_path, user_id):
170
+ # print(f"πŸ’‘ [DEBUG] Sending image to backend | img_path={img_path}, user_id={user_id}")
171
+
172
+ # if not user_id:
173
+ # print("❌ [DEBUG] Missing user_id in URL.")
174
+ # return "❌ user_id not found in URL."
175
+
176
+ # if not img_path or not os.path.exists(img_path):
177
+ # print("⚠️ [DEBUG] Image path invalid or does not exist.")
178
+ # return "⚠️ No image selected or image not found."
179
+
180
+ # try:
181
+ # with open(img_path, 'rb') as f:
182
+ # files = {'file': ('generated_image.png', f, 'image/png')}
183
+ # url = f"https://e335-103-40-74-83.ngrok-free.app/images/upload/{user_id}"
184
+ # print(f"πŸ” [DEBUG] Sending POST to {url}")
185
+ # response = requests.post(url, files=files)
186
+
187
+ # print(f"πŸ“© [DEBUG] Response: {response.status_code} - {response.text}")
188
+ # if response.status_code == 201 or response.status_code == 200:
189
+ # return "βœ… Image uploaded and saved to database!"
190
+ # else:
191
+ # return f"❌ Upload failed: {response.status_code} - {response.text}"
192
+
193
+ # except Exception as e:
194
+ # print(f"⚠️ [ERROR] Exception during upload: {str(e)}")
195
+ # return f"⚠️ Error: {str(e)}"
196
+
197
+
198
 
199
 
200