Spaces:
Build error
Build error
File size: 1,120 Bytes
0050b5d |
1 2 3 4 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 |
import os
from dotenv import load_dotenv
from langchain_groq import ChatGroq
from mcp_use import MCPAgent, MCPClient
import gradio as gr
# Load environment variables
load_dotenv()
os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
config_file = "browser_mcp.json"
client = MCPClient.from_config_file(config_file)
llm = ChatGroq(model="llama3-8b-8192")
agent = MCPAgent(llm=llm, client=client, max_steps=15, memory_enabled=True)
def chat(user_input, history=[]):
if user_input.lower() == "clear":
agent.clear_conversation_history()
return "", []
response = agent.run(user_input)
history = history + [[user_input, response]]
return "", history
with gr.Blocks() as demo:
gr.Markdown("# MCP Chatbot")
chatbot = gr.Chatbot()
msg = gr.Textbox(label="Type your message")
clear = gr.Button("Clear Conversation")
def respond(message, chat_history):
_, updated_history = chat(message, chat_history)
return "", updated_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
clear.click(lambda: ("", []), None, [msg, chatbot])
demo.launch() |