ok
Browse files- src/streamlit_app.py +22 -27
src/streamlit_app.py
CHANGED
|
@@ -1,50 +1,45 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
-
from huggingface_hub import login
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
# -----------------------------
|
| 7 |
-
#
|
| 8 |
-
# -----------------------------
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
login(token=HF_TOKEN)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
# Streamlit UI
|
| 16 |
-
# -----------------------------
|
| 17 |
-
st.set_page_config(page_title="AI Chatbot")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
st.write("Chat with Llama 3.2 1B Instruct")
|
| 22 |
-
|
| 23 |
-
# -----------------------------
|
| 24 |
# Load Model
|
| 25 |
-
# -----------------------------
|
| 26 |
@st.cache_resource
|
| 27 |
def load_model():
|
| 28 |
|
| 29 |
generator = pipeline(
|
| 30 |
"text-generation",
|
| 31 |
-
model="
|
| 32 |
-
device_map="auto"
|
| 33 |
)
|
| 34 |
|
| 35 |
return generator
|
| 36 |
|
|
|
|
| 37 |
generator = load_model()
|
| 38 |
|
| 39 |
-
# -----------------------------
|
| 40 |
-
#
|
| 41 |
-
# -----------------------------
|
| 42 |
-
user_input = st.text_area(
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
# -----------------------------
|
| 45 |
# Generate Response
|
| 46 |
-
# -----------------------------
|
| 47 |
-
if st.button("Generate"):
|
| 48 |
|
| 49 |
if user_input.strip() != "":
|
| 50 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# --------------------------------
|
| 5 |
+
# Streamlit Page Settings
|
| 6 |
+
# --------------------------------
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="AI Chatbot",
|
| 9 |
+
layout="centered"
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
st.title("🤖 AI Chatbot")
|
|
|
|
| 13 |
|
| 14 |
+
st.write("Chat with MiniCPM 1B model")
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# --------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Load Model
|
| 18 |
+
# --------------------------------
|
| 19 |
@st.cache_resource
|
| 20 |
def load_model():
|
| 21 |
|
| 22 |
generator = pipeline(
|
| 23 |
"text-generation",
|
| 24 |
+
model="openbmb/MiniCPM5-1B"
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
return generator
|
| 28 |
|
| 29 |
+
# Load the model
|
| 30 |
generator = load_model()
|
| 31 |
|
| 32 |
+
# --------------------------------
|
| 33 |
+
# User Input
|
| 34 |
+
# --------------------------------
|
| 35 |
+
user_input = st.text_area(
|
| 36 |
+
"Enter your prompt:"
|
| 37 |
+
)
|
| 38 |
|
| 39 |
+
# --------------------------------
|
| 40 |
# Generate Response
|
| 41 |
+
# --------------------------------
|
| 42 |
+
if st.button("Generate Response"):
|
| 43 |
|
| 44 |
if user_input.strip() != "":
|
| 45 |
|