tushar-r-pawar commited on
Commit
6562504
·
verified ·
1 Parent(s): b52e376

Update app.py

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