import streamlit as st import requests # Function to query the Hugging Face model def query(data): headers = { "Content-Type": "application/json", "Authorization": "Bearer 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" } response = requests.post( "https://api-inference.huggingface.co/models/h2oai/h2ogpt-gm-oasst1-en-1024-12b", headers=headers, json={"inputs": data} ) result = response.json() return result.get("generated_text", "No response") # Streamlit app def main(): st.title("Hugging Face Chatbot") st.write("Enter a message to chat with the model:") # Input text box user_input = st.text_area("Your Message", "") if st.button("Submit"): if user_input: st.write("User: ", user_input) try: response = query(user_input) st.write("Chatbot: ", response) except Exception as e: st.error(f"An error occurred: {str(e)}") if __name__ == "__main__": main()