Upload 2 files
Browse files- app.py +35 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
|
| 2 |
+
from pypdf import PdfReader
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# 1. Define a tool to read your CV
|
| 6 |
+
@tool
|
| 7 |
+
def read_cv(query: str) -> str:
|
| 8 |
+
"""
|
| 9 |
+
Reads the user's CV PDF and returns relevant text to answer questions.
|
| 10 |
+
Args:
|
| 11 |
+
query: The specific topic to look for in the CV.
|
| 12 |
+
"""
|
| 13 |
+
reader = PdfReader("My_CV.pdf")
|
| 14 |
+
text = ""
|
| 15 |
+
for page in reader.pages:
|
| 16 |
+
text += page.extract_text()
|
| 17 |
+
# In a production app, you'd use a vector search here,
|
| 18 |
+
# but for a single CV, passing the text works well.
|
| 19 |
+
return text[:2000] # Return first 2000 chars for context
|
| 20 |
+
|
| 21 |
+
# 2. Initialize the Agent
|
| 22 |
+
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 23 |
+
agent = CodeAgent(
|
| 24 |
+
tools=[DuckDuckGoSearchTool(), read_cv],
|
| 25 |
+
model=model,
|
| 26 |
+
add_base_tools=True
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def chat_interface(message, history):
|
| 30 |
+
prompt = f"You are a personal assistant for [Your Name]. Use the read_cv tool to answer questions about their background. If the user asks about companies or events they were involved in, use the web search tool to find more context. Query: {message}"
|
| 31 |
+
return agent.run(prompt)
|
| 32 |
+
|
| 33 |
+
# 3. Launch the API
|
| 34 |
+
demo = gr.ChatInterface(fn=chat_interface, title="Agentic CV Bot")
|
| 35 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smolagents==1.13.0
|
| 2 |
+
gradio
|
| 3 |
+
huggingface_hub
|
| 4 |
+
numpy
|
| 5 |
+
duckduckgo_search
|
| 6 |
+
pandas
|
| 7 |
+
pypdf
|
| 8 |
+
torch
|