Auxomatorsppt / app.py
BruceWayne1's picture
Update app.py
2ce0672 verified
import gradio as gr
import requests
import json
MCP_SERVER_URL = "http://127.0.0.1:8000" # internal port for MCP server
def respond(
message,
history: list[dict[str, str]],
system_message,
tool_name,
hf_token: gr.OAuthToken, # still needed if you want HF login
):
"""
Replace model-based response with MCP server tool call.
"""
try:
# build request payload
payload = {
"tool_name": tool_name,
"arguments": {"input": message, "history": history, "system": system_message}
}
resp = requests.post(f"{MCP_SERVER_URL}/tool", json=payload, timeout=120)
resp.raise_for_status()
data = resp.json()
# return response
response = json.dumps(data, indent=2, ensure_ascii=False)
yield response
except Exception as e:
yield f"❌ Error: {e}"
# Gradio UI
chatbot = gr.ChatInterface(
respond,
type="messages",
additional_inputs=[
gr.Textbox(value="You are interacting with PowerPoint MCP.", label="System message"),
gr.Textbox(value="create_presentation", label="Tool name"),
],
)
with gr.Blocks() as demo:
with gr.Sidebar():
gr.LoginButton()
chatbot.render()
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)