# import altair as alt # import numpy as np # import pandas as pd # import streamlit as st # """ # # Welcome to Streamlit! # Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:. # If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community # forums](https://discuss.streamlit.io). # In the meantime, below is an example of what you can do with just a few lines of code: # """ # num_points = st.slider("Number of points in spiral", 1, 10000, 1100) # num_turns = st.slider("Number of turns in spiral", 1, 300, 31) # indices = np.linspace(0, 1, num_points) # theta = 2 * np.pi * num_turns * indices # radius = indices # x = radius * np.cos(theta) # y = radius * np.sin(theta) # df = pd.DataFrame({ # "x": x, # "y": y, # "idx": indices, # "rand": np.random.randn(num_points), # }) # st.altair_chart(alt.Chart(df, height=700, width=700) # .mark_point(filled=True) # .encode( # x=alt.X("x", axis=None), # y=alt.Y("y", axis=None), # color=alt.Color("idx", legend=None, scale=alt.Scale()), # size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])), # )) import streamlit as st import asyncio import nest_asyncio from your_chatbot_module import MCP_ChatBot # Assuming you put your chatbot code in a module nest_asyncio.apply() @st.cache_resource def get_chatbot_instance(): api_key = st.secrets["LLAMA_API_KEY"] # Use Hugging Face Secrets for API key return MCP_ChatBot(api_key=api_key) chatbot = get_chatbot_instance() st.title("MCP Chatbot on Hugging Face Spaces") user_input = st.text_input("Enter your query:") if st.button("Send") and user_input: # Run the async chatbot query in the event loop response_steps = asyncio.run(chatbot.connect_and_process(user_input)) # Extract final answer from steps final_answer = "" for step in response_steps: if step.get("type") == "final_answer": final_answer = step.get("content") break st.markdown("### Response:") st.write(final_answer)