| | |
| | import os |
| | import getpass |
| | os.environ["OPENAI_API_KEY"] = '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' |
| |
|
| |
|
| | |
| | from llama_index.core import VectorStoreIndex, download_loader |
| | import gradio as gr |
| |
|
| | |
| | PDFReader = download_loader("PDFReader") |
| |
|
| | |
| | index = None |
| | query_engine = None |
| |
|
| | |
| | def process_resume(file): |
| | global index, query_engine |
| | try: |
| | file_path = file.name |
| |
|
| | loader = PDFReader() |
| | documents = loader.load_data(file_path) |
| |
|
| | index = VectorStoreIndex.from_documents(documents) |
| | query_engine = index.as_query_engine() |
| |
|
| | return "β
Resume uploaded and indexed successfully." |
| | except Exception as e: |
| | return f"β Error processing resume: {str(e)}" |
| |
|
| | |
| | def query_resume(question): |
| | global query_engine |
| | if not query_engine: |
| | return "β Please upload a resume first." |
| | try: |
| | response = query_engine.query(question) |
| | return str(response) |
| | except Exception as e: |
| | return f"β Error during query: {str(e)}" |
| |
|
| | |
| | upload_interface = gr.Interface( |
| | fn=process_resume, |
| | inputs=gr.File(label="Upload Resume (PDF)", file_types=[".pdf"]), |
| | outputs="text", |
| | title="π Resume Uploader", |
| | description="Upload your PDF resume to enable question-answering." |
| | ) |
| |
|
| | |
| | query_interface = gr.Interface( |
| | fn=query_resume, |
| | inputs=gr.Textbox(lines=2, placeholder="Ask something like: What are my skills?"), |
| | outputs="text", |
| | title="π€ Resume Query Bot", |
| | description="Ask questions about your uploaded resume.", |
| | examples=[ |
| | ["What is my email?"], |
| | ["What are my technical skills?"], |
| | ["List the projects I have done."], |
| | ["Where did I study?"], |
| | ["Do I have any certifications?"] |
| | ] |
| | ) |
| |
|
| | |
| | app = gr.TabbedInterface( |
| | interface_list=[upload_interface, query_interface], |
| | tab_names=["Upload Resume", "Ask Questions"] |
| | ) |
| |
|
| | |
| | app.launch(share=True) |