Spaces:
Sleeping
Sleeping
delete files
Browse filesFiles changed (2)
- src/streamlit_app.py+30-38
- streamlit_app.pyDeleted-32
12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st"""# Welcome to Streamlit!Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).In the meantime, below is an example of what you can do with just a few lines of code:"""num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indicesx = radius * np.cos(theta)y = radius * np.sin(theta)df = pd.DataFrame({"x": x,"y": y,"idx": indices,"rand": np.random.randn(num_points),})st.altair_chart(alt.Chart(df, height=700, width=700).mark_point(filled=True).encode(x=alt.X("x", axis=None),y=alt.Y("y", axis=None),color=alt.Color("idx", legend=None, scale=alt.Scale()),size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),))1234567891011121314151617181920212223242526272829303132import streamlit as stfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch# Titolo dell'appst.title("π€ Chatbot DeepSeek Transformers + Streamlit")@st.cache_resourcedef load_model():model_name = "deepseek-ai/DeepSeek-Coder-V2-Instruct"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")return tokenizer, modeltokenizer, model = load_model()if "chat_history" not in st.session_state:st.session_state.chat_history = []user_input = st.text_input("Scrivi il tuo messaggio:")if user_input:st.session_state.chat_history.append(("π§", user_input))inputs = tokenizer(user_input, return_tensors="pt").to(model.device)outputs = model.generate(**inputs, max_new_tokens=256, do_sample=True, temperature=0.7)response = tokenizer.decode(outputs[0], skip_special_tokens=True)st.session_state.chat_history.append(("π€", response))for speaker, msg in st.session_state.chat_history:st.markdown(f"**{speaker}**: {msg}")
1234567891011121314151617181920212223242526272829303132import streamlit as stfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch
# Titolo dell'appst.title("π€ Chatbot DeepSeek Transformers + Streamlit")
@st.cache_resourcedef load_model(): model_name = "deepseek-ai/DeepSeek-Coder-V2-Instruct" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto") return tokenizer, model
tokenizer, model = load_model()
if "chat_history" not in st.session_state: st.session_state.chat_history = []
user_input = st.text_input("Scrivi il tuo messaggio:")
if user_input: st.session_state.chat_history.append(("π§", user_input))
inputs = tokenizer(user_input, return_tensors="pt").to(model.device) outputs = model.generate(**inputs, max_new_tokens=256, do_sample=True, temperature=0.7) response = tokenizer.decode(outputs[0], skip_special_tokens=True)
st.session_state.chat_history.append(("π€", response))
for speaker, msg in st.session_state.chat_history: st.markdown(f"**{speaker}**: {msg}")src/streamlit_app.py+30-38
streamlit_app.pyDeleted-32