rca123456 commited on
Commit
4e07f0e
·
verified ·
1 Parent(s): 86391d1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import os
4
+ os.environ['OPENAI_API_KEY'] = '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' # Replace with your key
5
+
6
+
7
+ import gradio as gr
8
+ from llama_index.readers.file import PDFReader
9
+ from llama_index.core import VectorStoreIndex
10
+ from llama_index.core.chat_engine.types import BaseChatEngine
11
+
12
+ # Globals
13
+ chat_engine: BaseChatEngine = None
14
+
15
+ # Function to process uploaded resume
16
+ def process_resume(file):
17
+ global chat_engine
18
+ reader = PDFReader()
19
+ documents = reader.load_data(file=file.name)
20
+ index = VectorStoreIndex.from_documents(documents)
21
+ chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=False)
22
+ return "✅ Resume uploaded and indexed! You can now ask questions."
23
+
24
+ # Chat function
25
+ def chat_with_resume(message, chat_history):
26
+ global chat_engine
27
+ if not chat_engine:
28
+ return "⚠️ Please upload a resume first.", chat_history
29
+ response = chat_engine.chat(message)
30
+ chat_history.append((message, response.response))
31
+ return "", chat_history
32
+
33
+ # Gradio UI
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown("# 📄 Resume Chatbot\nUpload your resume and ask questions about your experience, skills, and more.")
36
+
37
+ with gr.Row():
38
+ file_input = gr.File(label="Upload Resume (PDF)", file_types=[".pdf"])
39
+ upload_button = gr.Button("Process Resume")
40
+
41
+ upload_output = gr.Textbox(label="Status")
42
+
43
+ upload_button.click(fn=process_resume, inputs=file_input, outputs=upload_output)
44
+
45
+ chatbot = gr.Chatbot(label="Chat with Resume")
46
+ message = gr.Textbox(placeholder="Ask something like: What are my key skills?", label="Your Question")
47
+ send = gr.Button("Send")
48
+
49
+ send.click(chat_with_resume, inputs=[message, chatbot], outputs=[message, chatbot])
50
+
51
+ demo.launch()