LamBDA / app.py
IvanLam's picture
Update app.py
9e681ae verified
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
from pypdf import PdfReader
import gradio as gr
# 1. Define a tool to read your CV
@tool
def read_cv(query: str) -> str:
"""
Reads the user's CV PDF and returns relevant text to answer questions.
Args:
query: The specific topic to look for in the CV.
"""
reader = PdfReader("My_CV.pdf")
text = ""
for page in reader.pages:
text += page.extract_text()
# In a production app, you'd use a vector search here,
# but for a single CV, passing the text works well.
return text[:2000] # Return first 2000 chars for context
# 2. Initialize the Agent
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
agent = CodeAgent(
tools=[DuckDuckGoSearchTool(), read_cv],
model=model,
add_base_tools=True
)
def chat_interface(message, history):
prompt = f"You are a personal assistant for Ivan. 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 DuckDuckGoSearchTool() web search tool to find more context. Query: {message}"
return agent.run(prompt)
# 3. Launch the API
demo = gr.ChatInterface(fn=chat_interface, title="Agentic CV Bot")
demo.launch()