sreepathi-ravikumar commited on
Commit
69f273b
·
verified ·
1 Parent(s): e0fe758

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -24
app.py CHANGED
@@ -61,6 +61,7 @@ def _payload(q: str):
61
  content=data[1]
62
  else:
63
  # For images, content must be an array with text + image
 
64
  content=[
65
  {
66
  "type": "text",
@@ -69,7 +70,7 @@ def _payload(q: str):
69
  {
70
  "type": "image_url",
71
  "image_url": {
72
- "url": data[1]
73
  }
74
  }
75
  ]
@@ -155,35 +156,15 @@ def askimage():
155
  return jsonify({"error": "No image provided"}), 400
156
 
157
  try:
158
- # Read and compress image
159
- image_bytes = image_file.read()
160
- img = Image.open(BytesIO(image_bytes))
161
-
162
- # Convert RGBA to RGB if needed
163
- if img.mode in ('RGBA', 'LA', 'P'):
164
- background = Image.new('RGB', img.size, (255, 255, 255))
165
- if img.mode == 'P':
166
- img = img.convert('RGBA')
167
- background.paste(img, mask=img.split()[-1] if img.mode == 'RGBA' else None)
168
- img = background
169
-
170
- # Resize if too large (keep reasonable size for hosting)
171
- max_size = (1920, 1080)
172
- img.thumbnail(max_size, Image.Resampling.LANCZOS)
173
-
174
- # Compress to JPEG
175
- output = BytesIO()
176
- img.convert('RGB').save(output, format='JPEG', quality=85, optimize=True)
177
- compressed_bytes = output.getvalue()
178
-
179
  # Upload to image hosting service and get URL
180
- image_url = upload_image_to_imgbb(compressed_bytes, image_file.filename)
 
181
 
182
  if not image_url:
183
  return jsonify({"error": "Failed to upload image"}), 500
184
 
185
  # Build prompt with direct URL
186
- prompt = "Image" + "%" + image_url + "%" + mode + "%" + lang
187
  print(f"Image URL: {image_url}")
188
 
189
  return Response(
 
61
  content=data[1]
62
  else:
63
  # For images, content must be an array with text + image
64
+ link="https://sreepathi-ravikumar-sample1.hf.space/"
65
  content=[
66
  {
67
  "type": "text",
 
70
  {
71
  "type": "image_url",
72
  "image_url": {
73
+ "url": link+data[1]
74
  }
75
  }
76
  ]
 
156
  return jsonify({"error": "No image provided"}), 400
157
 
158
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  # Upload to image hosting service and get URL
160
+ image_url = os.path.join("imagefile",image_file.filename)
161
+ image_file.save(image_url)
162
 
163
  if not image_url:
164
  return jsonify({"error": "Failed to upload image"}), 500
165
 
166
  # Build prompt with direct URL
167
+ prompt = "Image"+"%"+image_url+"%"+mode+"%"+lang
168
  print(f"Image URL: {image_url}")
169
 
170
  return Response(