|
|
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool |
|
|
from pypdf import PdfReader |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
@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() |
|
|
|
|
|
|
|
|
return text[:2000] |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
demo = gr.ChatInterface(fn=chat_interface, title="Agentic CV Bot") |
|
|
demo.launch() |