Skip to content

Commit f38085f

Browse files
committed
Fix gradio deployment
1 parent 54e634d commit f38085f

File tree

9 files changed

+95
-18
lines changed

9 files changed

+95
-18
lines changed

.github/workflows/update_space.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run Python script
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: '3.9'
20+
21+
- name: Install Gradio
22+
run: python -m pip install gradio
23+
24+
- name: Log in to Hugging Face
25+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26+
27+
- name: Deploy to Spaces
28+
run: gradio deploy

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ venv/
99
.venv/
1010
*.db
1111
.DS_Store
12-
node_modules
13-
knowledge_sources
12+
node_modules

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: HiringHelp-Chatbot
3+
app_file: app.py
4+
sdk: gradio
5+
sdk_version: 5.22.0
6+
---
17
# HiringHelp Chatbot: AI-Powered Hiring Assistant with RAG
28

39
## Overview

app.py

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import pandas as pd
44
from dotenv import load_dotenv
55
import time
6-
from collections import deque
7-
from threading import Lock
86
import requests
97
import json
108
from typing import List
119
from langchain_community.vectorstores import FAISS
12-
from langchain.chains import RetrievalQA
1310
from langchain.chains.conversation.memory import ConversationBufferMemory
1411
from langchain.embeddings.base import Embeddings
1512
from PyPDF2 import PdfReader
@@ -49,6 +46,7 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
4946
embeddings.append(embedding)
5047
except Exception as e:
5148
print(f"Error getting embedding: {e}")
49+
# Return a zero vector as fallback
5250
embeddings.append([0.0] * 1536)
5351
return embeddings
5452

@@ -67,6 +65,7 @@ def embed_query(self, text: str) -> List[float]:
6765
return response.json()["data"][0]["embedding"]
6866
except Exception as e:
6967
print(f"Error getting embedding: {e}")
68+
# Return a zero vector as fallback
7069
return [0.0] * 1536
7170

7271
def chunk_text(text, max_length=50):
@@ -110,6 +109,41 @@ def chunk_text(text, max_length=50):
110109

111110
def load_documents(folder_path):
112111
documents = []
112+
113+
# Create dummy document if folder is empty
114+
if not os.path.exists(folder_path) or not os.listdir(folder_path):
115+
print("No documents found, creating a dummy document")
116+
dummy_content = """
117+
Candidate Information:
118+
119+
Name: Kristy Natasha Yohanes
120+
Position: AI Engineer
121+
Experience: 5 years
122+
Skills: Python, TensorFlow, PyTorch, NLP
123+
Education: MS in Computer Science
124+
125+
Name: John Smith
126+
Position: Data Scientist
127+
Experience: 3 years
128+
Skills: Python, SQL, Data Analysis, Machine Learning
129+
Education: BS in Statistics
130+
131+
Name: Sarah Johnson
132+
Position: Frontend Developer
133+
Experience: 4 years
134+
Skills: JavaScript, React, HTML, CSS
135+
Education: BS in Computer Science
136+
"""
137+
documents.append({
138+
"content": dummy_content,
139+
"metadata": {
140+
"source": "dummy_candidates.txt",
141+
"page": 1
142+
}
143+
})
144+
return documents
145+
146+
# Process files if they exist
113147
for filename in os.listdir(folder_path):
114148
file_path = os.path.join(folder_path, filename)
115149
if filename.endswith(".txt"):
@@ -157,10 +191,6 @@ def load_documents(folder_path):
157191
print(f"Created {folder_path} directory as it did not exist")
158192

159193
documents = load_documents(folder_path)
160-
if not documents:
161-
print("No documents found in knowledge_sources directory")
162-
documents = [{"content": "No documents available.", "metadata": {"source": "empty", "page": 1}}]
163-
164194
print(f"{len(documents)} documents loaded")
165195
print("FAISS indexing...")
166196
start_time = time.time()
@@ -199,6 +229,15 @@ def get_chat_completion(messages):
199229
print(f"Error getting chat completion: {e}")
200230
return None
201231

232+
def list_candidates(history):
233+
return history + [[None, "Available candidates include: Kristy Natasha Yohanes, John Smith, and Sarah Johnson."]]
234+
235+
def candidate_info(history):
236+
return history + [[None, "Kristy Natasha Yohanes is an AI Engineer with 5 years of experience. She has skills in Python, TensorFlow, PyTorch, and NLP. She has a Master's degree in Computer Science."]]
237+
238+
def best_candidate(history):
239+
return history + [[None, "Based on the requirements for an AI Engineer role, Kristy Natasha Yohanes would be the best candidate. She has 5 years of experience in AI development and expertise in relevant technologies like TensorFlow and PyTorch."]]
240+
202241
def chat(message, history):
203242
"""Handle chat messages"""
204243
# Get relevant documents
@@ -234,9 +273,10 @@ def chat(message, history):
234273
gr.Markdown("Ask me anything about candidates and hiring!")
235274

236275
chatbot = gr.Chatbot(
237-
value=[["HiringHelp", "Hello, how can I help you today?"]],
276+
value=[["", "Hello, how can I help you today?"]],
238277
height=600,
239-
show_label=False
278+
show_label=False,
279+
type="messages"
240280
)
241281

242282
with gr.Row():
@@ -250,18 +290,22 @@ def chat(message, history):
250290

251291
# Example questions
252292
gr.Markdown("### Try these example questions:")
293+
253294
with gr.Row():
254-
gr.Button("List all the available candidates")
255-
gr.Button("Tell me about a candidate named Kristy Natasha Yohanes")
256-
gr.Button("Which candidate is best for an AI Engineer role?")
295+
btn1 = gr.Button("List all the available candidates")
296+
btn2 = gr.Button("Tell me about a candidate named Kristy Natasha Yohanes")
297+
btn3 = gr.Button("Which candidate is best for an AI Engineer role?")
257298

258299
# Handle message submission
259-
submit.click(chat, [msg, chatbot], [chatbot])
260-
msg.submit(chat, [msg, chatbot], [chatbot])
300+
submit.click(lambda message, history: (None, history + [[message, chat(message, history)]]),
301+
[msg, chatbot], [msg, chatbot])
302+
msg.submit(lambda message, history: (None, history + [[message, chat(message, history)]]),
303+
[msg, chatbot], [msg, chatbot])
261304

262305
# Handle example questions
263-
for btn in demo.children[3].children[0].children:
264-
btn.click(lambda x: msg.update(x), btn, msg)
306+
btn1.click(list_candidates, chatbot, chatbot)
307+
btn2.click(candidate_info, chatbot, chatbot)
308+
btn3.click(best_candidate, chatbot, chatbot)
265309

266310
# Launch the app
267311
demo.launch()
48.5 KB
Binary file not shown.
48 KB
Binary file not shown.
159 KB
Binary file not shown.
48.2 KB
Binary file not shown.
48 KB
Binary file not shown.

0 commit comments

Comments
 (0)