Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,79 +1,82 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
-
import streamlit as st
|
| 4 |
-
import airllm
|
| 5 |
-
|
| 6 |
-
# Load GEMMA 2B model and tokenizer
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
st.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
st.
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
"""
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import airllm
|
| 5 |
+
|
| 6 |
+
# Load GEMMA 2B model and tokenizer
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-27b")
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
"google/gemma-2-27b",
|
| 10 |
+
device_map="auto",
|
| 11 |
+
torch_dtype=torch.bfloat16
|
| 12 |
+
)
|
| 13 |
+
# Load the base version of the model
|
| 14 |
+
#model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 15 |
+
|
| 16 |
+
# Initialize AirLLM
|
| 17 |
+
air_llm = airllm.AirLLM(model, tokenizer)
|
| 18 |
+
|
| 19 |
+
# Streamlit app configuration
|
| 20 |
+
st.set_page_config(
|
| 21 |
+
page_title="Chatbot with GEMMA 2B and AirLLM",
|
| 22 |
+
page_icon="🤖",
|
| 23 |
+
layout="wide",
|
| 24 |
+
initial_sidebar_state="expanded",
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# App title
|
| 28 |
+
st.title("Conversational Chatbot with GEMMA 2B and AirLLM")
|
| 29 |
+
|
| 30 |
+
# Sidebar configuration
|
| 31 |
+
st.sidebar.header("Chatbot Configuration")
|
| 32 |
+
theme = st.sidebar.selectbox("Choose a theme", ["Default", "Dark", "Light"])
|
| 33 |
+
|
| 34 |
+
# Set theme based on user selection
|
| 35 |
+
if theme == "Dark":
|
| 36 |
+
st.markdown(
|
| 37 |
+
"""
|
| 38 |
+
<style>
|
| 39 |
+
.reportview-container {
|
| 40 |
+
background: #2E2E2E;
|
| 41 |
+
color: #FFFFFF;
|
| 42 |
+
}
|
| 43 |
+
.sidebar .sidebar-content {
|
| 44 |
+
background: #333333;
|
| 45 |
+
}
|
| 46 |
+
</style>
|
| 47 |
+
""",
|
| 48 |
+
unsafe_allow_html=True
|
| 49 |
+
)
|
| 50 |
+
elif theme == "Light":
|
| 51 |
+
st.markdown(
|
| 52 |
+
"""
|
| 53 |
+
<style>
|
| 54 |
+
.reportview-container {
|
| 55 |
+
background: #FFFFFF;
|
| 56 |
+
color: #000000;
|
| 57 |
+
}
|
| 58 |
+
.sidebar .sidebar-content {
|
| 59 |
+
background: #F5F5F5;
|
| 60 |
+
}
|
| 61 |
+
</style>
|
| 62 |
+
""",
|
| 63 |
+
unsafe_allow_html=True
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Chat input and output
|
| 67 |
+
user_input = st.text_input("You: ", "")
|
| 68 |
+
if st.button("Send"):
|
| 69 |
+
if user_input:
|
| 70 |
+
# Generate response using AirLLM
|
| 71 |
+
response = air_llm.generate_response(user_input)
|
| 72 |
+
st.text_area("Bot:", value=response, height=200, max_chars=None)
|
| 73 |
+
else:
|
| 74 |
+
st.warning("Please enter a message.")
|
| 75 |
+
|
| 76 |
+
# Footer
|
| 77 |
+
st.sidebar.markdown(
|
| 78 |
+
"""
|
| 79 |
+
### About
|
| 80 |
+
This is a conversational chatbot built using the base version of the GEMMA 2B model and AirLLM.
|
| 81 |
+
"""
|
| 82 |
+
)
|