HumeraAI/my-bot
0
1import streamlit as st2import requests3 4API_URL = "https://api-inference.huggingface.co/models/YOUR_MODEL_NAME"5HEADERS = {"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"}6 7def chat_with_model(prompt):8 response = requests.post(API_URL, headers=HEADERS, json={"inputs": prompt})9 return response.json()10 11st.title("🤖 My Chatbot")12 13if "chat" not in st.session_state:14 st.session_state.chat = []15 16for msg in st.session_state.chat:17 with st.chat_message(msg["role"]):18 st.write(msg["content"])19 20user_input = st.chat_input("Type a message...")21 22if user_input:23 st.session_state.chat.append({"role": "user", "content": user_input})24 25 result = chat_with_model(user_input)26 27 try:28 bot_reply = result[0]["generated_text"]29 except:30 bot_reply = str(result)31 32 st.session_state.chat.append({"role": "assistant", "content": bot_reply})33 34 st.rerun()