Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- src/streamlit_app.py +10 -1
src/streamlit_app.py
CHANGED
@@ -1,10 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Titolo dell'app
|
6 |
-
st.title("π€ Chatbot DeepSeek Transformers + Streamlit")
|
7 |
|
|
|
8 |
@st.cache_resource
|
9 |
def load_model():
|
10 |
model_name = "deepseek-ai/DeepSeek-Coder-V2-Instruct"
|
@@ -14,11 +19,14 @@ def load_model():
|
|
14 |
|
15 |
tokenizer, model = load_model()
|
16 |
|
|
|
17 |
if "chat_history" not in st.session_state:
|
18 |
st.session_state.chat_history = []
|
19 |
|
|
|
20 |
user_input = st.text_input("Scrivi il tuo messaggio:")
|
21 |
|
|
|
22 |
if user_input:
|
23 |
st.session_state.chat_history.append(("π§", user_input))
|
24 |
|
@@ -28,5 +36,6 @@ if user_input:
|
|
28 |
|
29 |
st.session_state.chat_history.append(("π€", response))
|
30 |
|
|
|
31 |
for speaker, msg in st.session_state.chat_history:
|
32 |
st.markdown(f"**{speaker}**: {msg}")
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Imposta la directory di cache locale
|
7 |
+
os.environ["TRANSFORMERS_CACHE"] = "./hf_cache"
|
8 |
|
9 |
# Titolo dell'app
|
10 |
+
st.title("π€ Chatbot DeepSeek con Transformers + Streamlit")
|
11 |
|
12 |
+
# Carica modello e tokenizer
|
13 |
@st.cache_resource
|
14 |
def load_model():
|
15 |
model_name = "deepseek-ai/DeepSeek-Coder-V2-Instruct"
|
|
|
19 |
|
20 |
tokenizer, model = load_model()
|
21 |
|
22 |
+
# Inizializza la sessione
|
23 |
if "chat_history" not in st.session_state:
|
24 |
st.session_state.chat_history = []
|
25 |
|
26 |
+
# Input utente
|
27 |
user_input = st.text_input("Scrivi il tuo messaggio:")
|
28 |
|
29 |
+
# Generazione risposta
|
30 |
if user_input:
|
31 |
st.session_state.chat_history.append(("π§", user_input))
|
32 |
|
|
|
36 |
|
37 |
st.session_state.chat_history.append(("π€", response))
|
38 |
|
39 |
+
# Mostra la conversazione
|
40 |
for speaker, msg in st.session_state.chat_history:
|
41 |
st.markdown(f"**{speaker}**: {msg}")
|