Spaces:
Sleeping
Sleeping
File size: 1,570 Bytes
50b7aea 3515d04 50b7aea 3515d04 50b7aea 3515d04 50b7aea 6c86404 50b7aea bf29456 6c86404 bf29456 6c86404 bf29456 6c86404 bf29456 6c86404 bf29456 6c86404 bf29456 50b7aea 6c86404 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import os
import gradio as gr
import openai
from llama_index.readers.file import PDFReader
from llama_index.core import VectorStoreIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
openai.api_key = os.environ.get("OPENAI_API_KEY")
def process_pdf(file, question):
try:
reader = PDFReader()
documents = reader.load_data(file=file.name)
embed_model = OpenAIEmbedding()
llm = OpenAI()
index = VectorStoreIndex.from_documents(documents, embed_model=embed_model)
query_engine = index.as_query_engine(llm=llm)
response = query_engine.query(question)
return str(response)
except Exception as e:
return f"β Error: {e}"
# Gradio Blocks UI
with gr.Blocks(title="Resume Analyzer by Advaith") as demo:
gr.Markdown("""
# π Resume Analyzer
Upload a resume and ask any question about the candidate!
Powered by **LlamaIndex** + **OpenAI**
""")
with gr.Row():
pdf_file = gr.File(label="π Upload your resume (PDF)", file_types=[".pdf"])
question = gr.Textbox(lines=2, label="π¬ Ask something", placeholder="e.g., What are the candidate's technical strengths?")
analyze_button = gr.Button("π Analyze")
result = gr.Textbox(label="π§ Answer", lines=10)
def run_analysis(file, question):
return process_pdf(file, question)
analyze_button.click(run_analysis, inputs=[pdf_file, question], outputs=result)
# Launch app
if __name__ == "__main__":
demo.launch()
|