Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def respond(
|
| 11 |
message,
|
|
@@ -25,8 +27,27 @@ def respond(
|
|
| 25 |
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
for message in client.chat_completion(
|
| 31 |
messages,
|
| 32 |
max_tokens=max_tokens,
|
|
@@ -34,31 +55,20 @@ def respond(
|
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
| 36 |
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly
|
| 50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
],
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
from fastmcp import FastMCPClient
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
# Set up inference client (LLM)
|
|
|
|
|
|
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
+
# Set up FastMCP client (replace with your actual MCP server URL)
|
| 10 |
+
mcp = FastMCPClient("Jobicy Remote Jobs Agent", url="https://oppaai-job-search-mcp-server.hf.space/gradio_api/mcp/sse")
|
| 11 |
|
| 12 |
def respond(
|
| 13 |
message,
|
|
|
|
| 27 |
|
| 28 |
messages.append({"role": "user", "content": message})
|
| 29 |
|
| 30 |
+
# Tool invocation keyword check (e.g., "search jobs for Python in Canada")
|
| 31 |
+
if "search jobs" in message.lower():
|
| 32 |
+
# Simple NLP parse: extract keyword, country, industry
|
| 33 |
+
# (You can improve this with spaCy or regex later)
|
| 34 |
+
keyword = message.split("for")[-1].strip().split(" in ")[0].strip()
|
| 35 |
+
country = message.split(" in ")[-1].strip() if " in " in message else ""
|
| 36 |
+
res = mcp.call_tool("search_jobs", inputs={"keyword": keyword, "country": country, "limit": 5})
|
| 37 |
+
|
| 38 |
+
if "error" in res:
|
| 39 |
+
return f"❌ {res['error']}"
|
| 40 |
+
if not res.get("jobs"):
|
| 41 |
+
return "No jobs found with those filters."
|
| 42 |
|
| 43 |
+
job_lines = [
|
| 44 |
+
f"**{j['title']}** at {j['company']} ({j['location']})\n{j['salary']}\nPosted: {j['pubDate']}\n[Apply Here]({j['url']})"
|
| 45 |
+
for j in res["jobs"]
|
| 46 |
+
]
|
| 47 |
+
return "\n\n---\n\n".join(job_lines)
|
| 48 |
+
|
| 49 |
+
# Fallback to LLM
|
| 50 |
+
response = ""
|
| 51 |
for message in client.chat_completion(
|
| 52 |
messages,
|
| 53 |
max_tokens=max_tokens,
|
|
|
|
| 55 |
temperature=temperature,
|
| 56 |
top_p=top_p,
|
| 57 |
):
|
| 58 |
+
token = message.choices[0].delta.content or ""
|
|
|
|
| 59 |
response += token
|
| 60 |
yield response
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
demo = gr.ChatInterface(
|
| 63 |
respond,
|
| 64 |
additional_inputs=[
|
| 65 |
+
gr.Textbox(value="You are a friendly assistant who can also help find remote jobs.", label="System message"),
|
| 66 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 67 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 68 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
],
|
| 70 |
+
title="Job Search Assistant Chatbot"
|
| 71 |
)
|
| 72 |
|
|
|
|
| 73 |
if __name__ == "__main__":
|
| 74 |
demo.launch()
|