Update main.py
Browse files24 unmodified lines25262728293031323344 unmodified lines7879808182838432 unmodified lines11711811912012112212324 unmodified lines# Configure Gemini APIsecret = os.environ["GEMINI"]genai.configure(api_key=secret)model_vision = genai.GenerativeModel('gemini-1.5-flash')model_text = genai.GenerativeModel('gemini-pro')44 unmodified lines@app.post("/get_ocr_data/")async def get_data(input_file: UploadFile = File(...)):#try:# Determine the file type by reading the first few bytesfile_content = await input_file.read()32 unmodified linesresponse = model_text.generate_content(prompt)print(response.text)data = json.loads(response.text.replace("JSON", "").replace("json", "").replace("```", ""))return {"data": data}#except Exception as e:#raise HTTPException(status_code=500, detail=f"Error processing file: {str(e)}")24 unmodified lines2526272829303132333444 unmodified lines7980818283848586878889909132 unmodified lines12412512612712812913024 unmodified lines# Configure Gemini APIsecret = os.environ["GEMINI"]SECRET_KEY = os.environ["SECRET_KEY"]genai.configure(api_key=secret)model_vision = genai.GenerativeModel('gemini-1.5-flash')model_text = genai.GenerativeModel('gemini-1.5-flash')44 unmodified lines@app.post("/get_ocr_data/")async def get_data(input_file: UploadFile = File(...),user_id:int,token:str):# To decode and verify the tokentry:decoded_payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])print(f"Decoded payload: {decoded_payload}")except:return "Invalid token"#try:# Determine the file type by reading the first few bytesfile_content = await input_file.read()32 unmodified linesresponse = model_text.generate_content(prompt)print(response.text)data = json.loads(response.text.replace("JSON", "").replace("json", "").replace("```", ""))return {"data": data,"user_id":user_id}#except Exception as e:#raise HTTPException(status_code=500, detail=f"Error processing file: {str(e)}")
main.py+10-3