Spaces:
Sleeping
Sleeping
Commit ·
027fad9
1
Parent(s): 975ef88
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
from chatterbot.trainers import ChatterBotCorpusTrainer
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
trainer.train("chatterbot.corpus.english")
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
# Create the Streamlit app
|
| 18 |
-
st.title("KviGPT Chatbot")
|
| 19 |
-
user_input = st.text_area("You:", height=200)
|
| 20 |
if st.button("Send"):
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
| 1 |
+
!pip install streamlit transformers
|
| 2 |
import streamlit as st
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 4 |
|
| 5 |
+
device = "cuda"
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1")
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1")
|
| 8 |
|
| 9 |
+
model.to(device)
|
|
|
|
| 10 |
|
| 11 |
+
def generate_text(prompt, max_new_tokens=100, do_sample=True):
|
| 12 |
+
model_inputs = tokenizer([prompt], return_tensors="pt").to(device)
|
| 13 |
+
generated_ids = model.generate(**model_inputs, max_new_tokens=max_new_tokens, do_sample=do_sample)
|
| 14 |
+
return tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
| 15 |
+
|
| 16 |
+
st.title("KviGPT - Hugging Face Chat")
|
| 17 |
+
|
| 18 |
+
user_input = st.text_input("You:", value="My favourite condiment is ")
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
if st.button("Send"):
|
| 21 |
+
prompt = user_input
|
| 22 |
+
model_response = generate_text(prompt)[0]
|
| 23 |
+
st.write("KviGPT:", model_response)
|