Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import warnings
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
| 6 |
+
|
| 7 |
+
if "pipe" not in st.session_state:
|
| 8 |
+
st.session_state.pipe = pipeline('text-generation', model='mistralai/Mixtral-8x7B-Instruct-v0.1')
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
st.title("Turk-GPT Chatbot")
|
| 12 |
+
st.caption("🚀 A streamlit chatbot")
|
| 13 |
+
if "messages" not in st.session_state:
|
| 14 |
+
st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
|
| 15 |
+
|
| 16 |
+
for msg in st.session_state.messages:
|
| 17 |
+
st.chat_message(msg["role"]).write(msg["content"])
|
| 18 |
+
|
| 19 |
+
if prompt := st.chat_input():
|
| 20 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 21 |
+
st.chat_message("user").write(prompt)
|
| 22 |
+
response = st.session_state.pipe(prompt, max_length=50)
|
| 23 |
+
msg = response[0]['generated_text']
|
| 24 |
+
st.session_state.messages.append({"role": "assistant", "content": msg})
|
| 25 |
+
st.chat_message("assistant").write(msg)
|