Spaces:
Running
Running
Upload 3 files
Browse files- Dockerfile +13 -0
- main.py +36 -0
- requirements.txt +9 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11-slim-buster
|
2 |
+
|
3 |
+
RUN apt update -y && apt install awscli -y
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
COPY . /app
|
8 |
+
|
9 |
+
RUN pip install -r requirements.txt
|
10 |
+
|
11 |
+
EXPOSE 8000
|
12 |
+
|
13 |
+
CMD [ "uvicorn", "--host", "0.0.0.0", "main:app" ]
|
main.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException
|
2 |
+
from fastapi.responses import JSONResponse
|
3 |
+
from typing import Any
|
4 |
+
import google.generativeai as genai
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
import io
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
app = FastAPI()
|
10 |
+
|
11 |
+
def get_gemini_response(image: bytes) -> Any:
|
12 |
+
image_stream = io.BytesIO(image)
|
13 |
+
image = Image.open(image_stream)
|
14 |
+
model = genai.GenerativeModel('gemini-1.5-flash',
|
15 |
+
generation_config={"response_mime_type": "application/json"})
|
16 |
+
inputtext = '''System: You are a dietitian, Please check below image and share calorific value of each dish in metric system. Also explain how
|
17 |
+
much you should eat at one time for healthy diet. Response should be as per below json format for each dish separately.
|
18 |
+
{"Dish_Name": ,
|
19 |
+
"calorific_value": ,
|
20 |
+
"Healthy serving_size": }.
|
21 |
+
If unable to identify the dish then respond with {"Dish_Name": Unable to identify the dish}.'''
|
22 |
+
response = model.generate_content([inputtext, image])
|
23 |
+
return response.text
|
24 |
+
|
25 |
+
@app.post("/analyze-dish")
|
26 |
+
async def analyze_dish(image: UploadFile = File(...)):
|
27 |
+
try:
|
28 |
+
image_bytes = await image.read()
|
29 |
+
result = get_gemini_response(image_bytes)
|
30 |
+
return JSONResponse(content=result)
|
31 |
+
except Exception as e:
|
32 |
+
raise HTTPException(status_code=500, detail=str(e))
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
import uvicorn
|
36 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|
4 |
+
pandas
|
5 |
+
json
|
6 |
+
fastapi
|
7 |
+
uvicorn
|
8 |
+
requests
|
9 |
+
ipykernel
|