Update main.py
Browse files
main.py
CHANGED
|
@@ -10,7 +10,13 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 10 |
from PyPDF2 import PdfReader
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
secret = os.environ["key"]
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
app = FastAPI()
|
| 16 |
|
|
@@ -33,8 +39,17 @@ async def get_data(pdf: UploadFile = File(...)):
|
|
| 33 |
for page in pdf_reader.pages:
|
| 34 |
text += page.extract_text()
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
raise HTTPException(status_code=500, detail=f"Error processing PDF: {str(e)}")
|
|
|
|
| 10 |
from PyPDF2 import PdfReader
|
| 11 |
|
| 12 |
|
| 13 |
+
import google.generativeai as genai
|
| 14 |
+
import json
|
| 15 |
+
|
| 16 |
secret = os.environ["key"]
|
| 17 |
+
genai.configure(api_key=secret)
|
| 18 |
+
model_vision = genai.GenerativeModel('gemini-pro-vision')
|
| 19 |
+
model_text = genai.GenerativeModel('gemini-pro')
|
| 20 |
|
| 21 |
app = FastAPI()
|
| 22 |
|
|
|
|
| 39 |
for page in pdf_reader.pages:
|
| 40 |
text += page.extract_text()
|
| 41 |
|
| 42 |
+
# call gemini to get required data extracted text
|
| 43 |
+
prompt = f"""this is cv data : {text.strip()}
|
| 44 |
+
i want only
|
| 45 |
+
|
| 46 |
+
fisrtname,lastname,contact number,total years of experince,linkdn link,experinece,skils
|
| 47 |
+
|
| 48 |
+
in json format only"""
|
| 49 |
+
|
| 50 |
+
response = model_text.generate_content(prompt)
|
| 51 |
+
data = json.loads(response.text.replace("```json","").replace("```",""))
|
| 52 |
+
return {"data":data}
|
| 53 |
|
| 54 |
except Exception as e:
|
| 55 |
raise HTTPException(status_code=500, detail=f"Error processing PDF: {str(e)}")
|