Fred808 commited on
Commit
4878be9
·
verified ·
1 Parent(s): 2db4615

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -45,13 +45,19 @@ async def chat_with_text(request: TextRequest):
45
  except Exception as e:
46
  raise HTTPException(status_code=500, detail=str(e))
47
 
48
- @app.post("/chat/image")
49
- async def chat_with_image(file: UploadFile = File(...)):
50
- # Read and encode the image file to base64
51
- image_data = await file.read()
52
- base64_image = base64.b64encode(image_data).decode("utf-8")
53
 
54
- # Prepare the payload for the NVIDIA API
 
 
 
 
 
 
 
 
 
 
 
55
  payload = {
56
  "model": "meta/llama-3.2-90b-vision-instruct",
57
  "messages": [
 
45
  except Exception as e:
46
  raise HTTPException(status_code=500, detail=str(e))
47
 
 
 
 
 
 
48
 
49
+
50
+ @app.post("/chat/image-url")
51
+ async def chat_with_image_url(request: ImageURLRequest):
52
+ try:
53
+ img_response = requests.get(request.url)
54
+ if img_response.status_code != 200:
55
+ raise HTTPException(status_code=400, detail="Failed to fetch image from URL")
56
+ image_data = img_response.content
57
+ base64_image = base64.b64encode(image_data).decode("utf-8")
58
+ except Exception as e:
59
+ raise HTTPException(status_code=400, detail=f"Image download failed: {e}")
60
+
61
  payload = {
62
  "model": "meta/llama-3.2-90b-vision-instruct",
63
  "messages": [