Spaces:
Running
Running
Create chatbot.py
Browse files- chatbot.py +32 -0
chatbot.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
@st.cache_resource
|
| 5 |
+
def load_model():
|
| 6 |
+
# Use a public 7B model (excellent quality)
|
| 7 |
+
return pipeline("text-generation", model="your-ammoncoder123/IPTchatbot")
|
| 8 |
+
|
| 9 |
+
pipe = load_model()
|
| 10 |
+
|
| 11 |
+
st.title("My 1.7B Smart Chatbot")
|
| 12 |
+
|
| 13 |
+
if "messages" not in st.session_state:
|
| 14 |
+
st.session_state.messages = []
|
| 15 |
+
|
| 16 |
+
for msg in st.session_state.messages:
|
| 17 |
+
with st.chat_message(msg["role"]):
|
| 18 |
+
st.markdown(msg["content"])
|
| 19 |
+
|
| 20 |
+
if prompt := st.chat_input("Ask about IPT/ICT..."):
|
| 21 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 22 |
+
with st.chat_message("user"):
|
| 23 |
+
st.markdown(prompt)
|
| 24 |
+
|
| 25 |
+
with st.chat_message("assistant"):
|
| 26 |
+
with st.spinner("Thinking..."):
|
| 27 |
+
response = pipe(prompt, max_new_tokens=300)[0]['generated_text']
|
| 28 |
+
st.markdown(response)
|
| 29 |
+
|
| 30 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 31 |
+
|
| 32 |
+
st.info("This is a 1.7B model demo — answers are generally accurate but verify important facts.")
|