Update main.py
Browse files
main.py
CHANGED
|
@@ -25,9 +25,10 @@ load_dotenv()
|
|
| 25 |
|
| 26 |
# Configure Gemini API
|
| 27 |
secret = os.environ["GEMINI"]
|
|
|
|
| 28 |
genai.configure(api_key=secret)
|
| 29 |
model_vision = genai.GenerativeModel('gemini-1.5-flash')
|
| 30 |
-
model_text = genai.GenerativeModel('gemini-
|
| 31 |
|
| 32 |
|
| 33 |
|
|
@@ -78,7 +79,13 @@ def vision(file_content):
|
|
| 78 |
|
| 79 |
|
| 80 |
@app.post("/get_ocr_data/")
|
| 81 |
-
async def get_data(input_file: UploadFile = File(...)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
#try:
|
| 83 |
# Determine the file type by reading the first few bytes
|
| 84 |
file_content = await input_file.read()
|
|
@@ -117,7 +124,7 @@ async def get_data(input_file: UploadFile = File(...)):
|
|
| 117 |
response = model_text.generate_content(prompt)
|
| 118 |
print(response.text)
|
| 119 |
data = json.loads(response.text.replace("JSON", "").replace("json", "").replace("```", ""))
|
| 120 |
-
return {"data": data}
|
| 121 |
|
| 122 |
#except Exception as e:
|
| 123 |
#raise HTTPException(status_code=500, detail=f"Error processing file: {str(e)}")
|
|
|
|
| 25 |
|
| 26 |
# Configure Gemini API
|
| 27 |
secret = os.environ["GEMINI"]
|
| 28 |
+
SECRET_KEY = os.environ["SECRET_KEY"]
|
| 29 |
genai.configure(api_key=secret)
|
| 30 |
model_vision = genai.GenerativeModel('gemini-1.5-flash')
|
| 31 |
+
model_text = genai.GenerativeModel('gemini-1.5-flash')
|
| 32 |
|
| 33 |
|
| 34 |
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
@app.post("/get_ocr_data/")
|
| 82 |
+
async def get_data(input_file: UploadFile = File(...),user_id:int,token:str):
|
| 83 |
+
# To decode and verify the token
|
| 84 |
+
try:
|
| 85 |
+
decoded_payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
|
| 86 |
+
print(f"Decoded payload: {decoded_payload}")
|
| 87 |
+
except:
|
| 88 |
+
return "Invalid token"
|
| 89 |
#try:
|
| 90 |
# Determine the file type by reading the first few bytes
|
| 91 |
file_content = await input_file.read()
|
|
|
|
| 124 |
response = model_text.generate_content(prompt)
|
| 125 |
print(response.text)
|
| 126 |
data = json.loads(response.text.replace("JSON", "").replace("json", "").replace("```", ""))
|
| 127 |
+
return {"data": data,"user_id":user_id}
|
| 128 |
|
| 129 |
#except Exception as e:
|
| 130 |
#raise HTTPException(status_code=500, detail=f"Error processing file: {str(e)}")
|