Nattyboi commited on
Commit
9fe38b7
·
verified ·
1 Parent(s): eab8d64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -5,7 +5,9 @@ from utils import google_search,split_text_into_chunks,insert_embeddings_into_pi
5
  from fastapi import FastAPI, File, UploadFile
6
  from fastapi.responses import JSONResponse
7
  import docx
8
- import fitz
 
 
9
  load_dotenv()
10
 
11
  CX = os.getenv("SEARCH_ENGINE_ID")
@@ -75,19 +77,28 @@ async def upload_file(user_id,file: UploadFile = File(...)):
75
 
76
 
77
 
78
-
79
  @app.get("/ask")
80
- def ask_ai_about_resume(query,user_id):
81
- context = query_vector_database(query=query,api_key=PINECONE_API_KEY,name_space=user_id)
82
- from google import genai
83
-
 
 
 
 
 
 
 
 
84
  client = genai.Client(api_key=GEMINI_API_KEY)
 
85
  response = client.models.generate_content(
86
- model="gemini-2.0-flash", contents=f"""
87
- Answer this question using the context provided
 
88
  question: {query}
89
  context: {context}
90
  """
91
  )
92
 
93
- return response.text
 
5
  from fastapi import FastAPI, File, UploadFile
6
  from fastapi.responses import JSONResponse
7
  import docx
8
+ import fitz
9
+ import asyncio
10
+ from google import genai
11
  load_dotenv()
12
 
13
  CX = os.getenv("SEARCH_ENGINE_ID")
 
77
 
78
 
79
 
 
80
  @app.get("/ask")
81
+ def ask_ai_about_resume(query, user_id):
82
+ # Retrieve context from your vector database
83
+ context = query_vector_database(query=query, api_key=PINECONE_API_KEY, name_space=user_id)
84
+
85
+ # Ensure that an event loop is present in this thread.
86
+ try:
87
+ loop = asyncio.get_event_loop()
88
+ except RuntimeError:
89
+ loop = asyncio.new_event_loop()
90
+ asyncio.set_event_loop(loop)
91
+
92
+ # Create the Gemini client after the event loop is set up
93
  client = genai.Client(api_key=GEMINI_API_KEY)
94
+
95
  response = client.models.generate_content(
96
+ model="gemini-2.0-flash",
97
+ contents=f"""
98
+ Answer this question using the context provided:
99
  question: {query}
100
  context: {context}
101
  """
102
  )
103
 
104
+ return response.text