JohnAlexander23 commited on
Commit
fd74ac9
·
verified ·
1 Parent(s): 39b87c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -6
app.py CHANGED
@@ -4,23 +4,85 @@ from groq import Groq
4
  # Define the API key here
5
  GROQ_API_KEY = "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"
6
 
 
 
 
 
 
 
7
  # Define function to fetch response
8
  def fetch_response(user_input):
9
  client = Groq(api_key=GROQ_API_KEY)
 
10
  chat_completion = client.chat.completions.create(
11
- messages=[
12
- {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper expamples to help the user. Try to mention references or provide citations to make it more detail oriented. "},
13
- {"role": "user", "content": user_input},
14
- ],
15
  model="mixtral-8x7b-32768",
16
  stream=False
17
  )
18
- return chat_completion.choices[0].message.content
 
 
19
 
20
  # Streamlit app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  st.title("Fastest AI Chatbot")
22
  st.write("Ask a question and get a response.")
23
 
 
 
 
 
 
 
 
24
  # Text input for user's question
25
  user_input = st.text_input("Enter your question here:")
26
 
@@ -33,7 +95,7 @@ if st.button("Get Response"):
33
  # Footer
34
  st.markdown(
35
  """
36
- <footer style="color: blue; font-size: small; text-align: right;">
37
  By DL TITANS
38
  </footer>
39
  """,
 
4
  # Define the API key here
5
  GROQ_API_KEY = "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"
6
 
7
+ # Initialize session state for chat history
8
+ if "chat_history" not in st.session_state:
9
+ st.session_state.chat_history = [
10
+ {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper examples to help the user. Try to mention references or provide citations to make it more detail-oriented."}
11
+ ]
12
+
13
  # Define function to fetch response
14
  def fetch_response(user_input):
15
  client = Groq(api_key=GROQ_API_KEY)
16
+ st.session_state.chat_history.append({"role": "user", "content": user_input})
17
  chat_completion = client.chat.completions.create(
18
+ messages=st.session_state.chat_history,
 
 
 
19
  model="mixtral-8x7b-32768",
20
  stream=False
21
  )
22
+ response = chat_completion.choices[0].message.content
23
+ st.session_state.chat_history.append({"role": "assistant", "content": response})
24
+ return response
25
 
26
  # Streamlit app
27
+ st.set_page_config(page_title="Fastest AI Chatbot", page_icon="🤖", layout="wide")
28
+
29
+ st.markdown(
30
+ """
31
+ <style>
32
+ body {
33
+ background-color: #2a2a2a;
34
+ color: #e1e1e1;
35
+ font-family: 'Courier New', Courier, monospace;
36
+ }
37
+ .css-18e3th9 {
38
+ padding: 2rem;
39
+ }
40
+ .css-1d391kg {
41
+ background: linear-gradient(145deg, #3e3e3e, #2a2a2a);
42
+ box-shadow: 20px 20px 60px #232323, -20px -20px 60px #323232;
43
+ border-radius: 15px;
44
+ padding: 2rem;
45
+ }
46
+ .stButton>button {
47
+ background: linear-gradient(145deg, #5e5e5e, #3a3a3a);
48
+ box-shadow: 8px 8px 16px #232323, -8px -8px 16px #323232;
49
+ color: #e1e1e1;
50
+ border: none;
51
+ border-radius: 12px;
52
+ padding: 0.5rem 2rem;
53
+ font-size: 1.2rem;
54
+ margin-top: 1rem;
55
+ }
56
+ .stTextInput>div>div>input {
57
+ background: linear-gradient(145deg, #5e5e5e, #3a3a3a);
58
+ box-shadow: inset 8px 8px 16px #232323, inset -8px -8px 16px #323232;
59
+ border: none;
60
+ border-radius: 12px;
61
+ color: #e1e1e1;
62
+ padding: 1rem;
63
+ font-size: 1rem;
64
+ }
65
+ footer {
66
+ color: #e1e1e1;
67
+ font-size: small;
68
+ text-align: right;
69
+ margin-top: 2rem;
70
+ }
71
+ </style>
72
+ """,
73
+ unsafe_allow_html=True
74
+ )
75
+
76
  st.title("Fastest AI Chatbot")
77
  st.write("Ask a question and get a response.")
78
 
79
+ # Display chat history
80
+ for chat in st.session_state.chat_history:
81
+ if chat["role"] == "user":
82
+ st.markdown(f"**You:** {chat['content']}")
83
+ elif chat["role"] == "assistant":
84
+ st.markdown(f"**AI:** {chat['content']}")
85
+
86
  # Text input for user's question
87
  user_input = st.text_input("Enter your question here:")
88
 
 
95
  # Footer
96
  st.markdown(
97
  """
98
+ <footer>
99
  By DL TITANS
100
  </footer>
101
  """,