Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,54 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
from
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
from tinyagents import Agent
|
| 5 |
+
|
| 6 |
+
# Set your Hugging Face API token
|
| 7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
+
|
| 9 |
+
# Define the MCP server URL
|
| 10 |
+
MCP_URL = "https://oppaai-job-search-mcp-server.hf.space/gradio_api/mcp/sse"
|
| 11 |
+
|
| 12 |
+
# Initialize the MCP client
|
| 13 |
+
mcp_client = InferenceClient(
|
| 14 |
+
url=MCP_URL,
|
| 15 |
+
token=HF_TOKEN
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# Fetch the tools exposed by the MCP server
|
| 19 |
+
tools = mcp_client.get_tools()
|
| 20 |
+
|
| 21 |
+
# Define the model to be used
|
| 22 |
+
model = InferenceClient(
|
| 23 |
+
model="Qwen/Qwen3-8B",
|
| 24 |
+
token=HF_TOKEN
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Create the agent
|
| 28 |
+
agent = Agent(
|
| 29 |
+
model=model,
|
| 30 |
+
tools=tools
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Define the function to handle user input and generate responses
|
| 34 |
+
def chat_fn(user_message, history):
|
| 35 |
+
history = history or []
|
| 36 |
+
history.append(("user", user_message))
|
| 37 |
+
response = agent.run(user_message)
|
| 38 |
+
history.append(("agent", response))
|
| 39 |
+
return history, history
|
| 40 |
+
|
| 41 |
+
# Set up the Gradio interface
|
| 42 |
+
with gr.Blocks() as demo:
|
| 43 |
+
chatbot = gr.Chatbot()
|
| 44 |
+
user_input = gr.Textbox(placeholder="Ask Jobcy about remote jobs or anything else...")
|
| 45 |
+
state = gr.State([])
|
| 46 |
+
|
| 47 |
+
user_input.submit(chat_fn, inputs=[user_input, state], outputs=[chatbot, state])
|
| 48 |
+
|
| 49 |
+
demo.title = "Jobcy Remote Job Search Assistant (tinyagents)"
|
| 50 |
+
demo.launch()
|
| 51 |
+
|
| 52 |
+
# Disconnect the MCP client when done
|
| 53 |
+
import atexit
|
| 54 |
+
atexit.register(mcp_client.disconnect)
|