Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,49 @@
|
|
| 1 |
-
import
|
| 2 |
import gradio as gr
|
| 3 |
-
from smolagents import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
reply = agent.run(message)
|
| 27 |
-
return reply
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
fn=respond,
|
| 32 |
-
title="Job Search Assistant (Agent)",
|
| 33 |
-
description="Ask me about job listings or general questions — I’ll use the job search tool when needed!",
|
| 34 |
-
)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 1 |
+
import re
|
| 2 |
import gradio as gr
|
| 3 |
+
from smolagents import Agent
|
| 4 |
+
from smolagents.mcp import MCPServerHTTP
|
| 5 |
+
from smolagents.models import HuggingFaceModel
|
| 6 |
+
from smolagents.providers import HuggingFaceProvider
|
| 7 |
+
|
| 8 |
+
# MCP Server SSE URL
|
| 9 |
+
SSE_URL = "https://oppaai-job-search-mcp-server.hf.space/gradio_api/mcp/sse"
|
| 10 |
+
server = MCPServerHTTP(url=SSE_URL)
|
| 11 |
+
|
| 12 |
+
# Use HF Qwen3-8B model from Hugging Face Hub
|
| 13 |
+
hf_model = HuggingFaceModel(
|
| 14 |
+
model_name="Qwen/Qwen-3-8B", # change this if you have exact repo name or path
|
| 15 |
+
provider=HuggingFaceProvider(
|
| 16 |
+
api_token="HF_TOKEN" # put your HF token here if required
|
| 17 |
+
)
|
| 18 |
+
)
|
| 19 |
|
| 20 |
+
# Create Agent with MCP Server
|
| 21 |
+
agent = Agent(
|
| 22 |
+
model=hf_model,
|
| 23 |
+
mcp_servers=[server],
|
| 24 |
+
instructions="""
|
| 25 |
+
Your name is Jobcy. You are an AI assistant designed to help users to find remote jobs by searching through job listings from various sources, including the Jobicy API and other platforms.
|
| 26 |
+
You will list the job listings in a structured format, including the job title, company, location, and the google search link.
|
| 27 |
+
""",
|
| 28 |
+
stream=False
|
| 29 |
)
|
| 30 |
|
| 31 |
+
def chat_with_agent(user_input, history):
|
| 32 |
+
history = history or []
|
| 33 |
+
history.append(("user", user_input))
|
| 34 |
|
| 35 |
+
result = agent.run(user_input)
|
| 36 |
+
cleaned_output = re.sub(r"<think>.*?</think>", "", result.output, flags=re.DOTALL).strip()
|
| 37 |
|
| 38 |
+
history.append(("agent", cleaned_output))
|
| 39 |
+
return history, history
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
chatbot = gr.Chatbot()
|
| 43 |
+
user_input = gr.Textbox(placeholder="Ask Jobcy about remote jobs or anything else...", label="Your Message")
|
| 44 |
+
state = gr.State([])
|
| 45 |
|
| 46 |
+
user_input.submit(chat_with_agent, inputs=[user_input, state], outputs=[chatbot, state])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
demo.title = "Jobcy Remote Job Search Assistant"
|
| 49 |
+
demo.launch()
|