Update src/streamlit_app.py
Browse files- src/streamlit_app.py +35 -39
src/streamlit_app.py
CHANGED
@@ -1,40 +1,36 @@
|
|
1 |
-
import altair as alt
|
2 |
-
import numpy as np
|
3 |
-
import pandas as pd
|
4 |
-
import streamlit as st
|
5 |
|
6 |
-
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
st.
|
34 |
-
.
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
import os
|
3 |
+
os.environ["MPLCONFIGDIR"] = "/tmp" # Prevent matplotlib config errors
|
4 |
+
os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
|
5 |
+
os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
|
6 |
+
|
7 |
+
import streamlit as st
|
8 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
9 |
+
import torch
|
10 |
+
|
11 |
+
# Title and UI
|
12 |
+
st.set_page_config(page_title="DeepSeek-R1 Chatbot", page_icon="🤖")
|
13 |
+
st.title("🧠 DeepSeek-R1 CPU Chatbot")
|
14 |
+
st.caption("Running entirely on CPU using Hugging Face Transformers")
|
15 |
+
|
16 |
+
# Load the model and tokenizer
|
17 |
+
@st.cache_resource
|
18 |
+
def load_model():
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-1.3B-base")
|
20 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-1.3B-base")
|
21 |
+
return tokenizer, model
|
22 |
+
|
23 |
+
|
24 |
+
tokenizer, model = load_model()
|
25 |
+
|
26 |
+
# Prompt input
|
27 |
+
user_input = st.text_area("📥 Enter your prompt here:", "Explain what a neural network is.")
|
28 |
+
|
29 |
+
if st.button("🧠 Generate Response"):
|
30 |
+
with st.spinner("Thinking..."):
|
31 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
32 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
33 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
34 |
+
|
35 |
+
st.markdown("### 🤖 Response:")
|
36 |
+
st.write(response)
|