|
import torch |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
import streamlit as st |
|
import airllm |
|
import os |
|
from airllm.auto_model import AutoModel |
|
from dotenv import load_dotenv |
|
|
|
load_dotenv() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") |
|
|
|
|
|
api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it", use_auth_token=api_token) |
|
model = AutoModelForCausalLM.from_pretrained( |
|
"google/gemma-2-9b-it", |
|
device_map="auto", |
|
torch_dtype=torch.bfloat16, |
|
use_auth_token=api_token |
|
) |
|
|
|
|
|
|
|
|
|
air_llm = airllm.AutoModel(model) |
|
|
|
|
|
st.set_page_config( |
|
page_title="Chatbot with GEMMA 27B and AirLLM", |
|
page_icon="π€", |
|
layout="wide", |
|
initial_sidebar_state="expanded", |
|
) |
|
|
|
|
|
st.title("Conversational Chatbot with GEMMA 27B and AirLLM") |
|
|
|
|
|
st.sidebar.header("Chatbot Configuration") |
|
theme = st.sidebar.selectbox("Choose a theme", ["Default", "Dark", "Light"]) |
|
|
|
|
|
if theme == "Dark": |
|
st.markdown( |
|
""" |
|
<style> |
|
.reportview-container { |
|
background: #2E2E2E; |
|
color: #FFFFFF; |
|
} |
|
.sidebar .sidebar-content { |
|
background: #333333; |
|
} |
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
elif theme == "Light": |
|
st.markdown( |
|
""" |
|
<style> |
|
.reportview-container { |
|
background: #FFFFFF; |
|
color: #000000; |
|
} |
|
.sidebar .sidebar-content { |
|
background: #F5F5F5; |
|
} |
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
|
|
user_input = st.text_input("You: ", "") |
|
if st.button("Send"): |
|
if user_input: |
|
|
|
response = air_llm.generate_response(user_input) |
|
st.text_area("Bot:", value=response, height=200, max_chars=None) |
|
else: |
|
st.warning("Please enter a message.") |
|
|
|
|
|
st.sidebar.markdown( |
|
""" |
|
### About |
|
This is a conversational chatbot built using the base version of the GEMMA 27B model and AirLLM. |
|
""" |
|
) |
|
|