Spaces:
Running
Running
miaohaiyuan
commited on
Commit
β’
846e270
1
Parent(s):
7a48cde
update app.py
Browse files- .gitignore +2 -0
- app.py +8 -5
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.streamlit/secrets.toml
|
2 |
+
.env
|
app.py
CHANGED
@@ -1,8 +1,11 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from typing import Generator
|
3 |
from groq import Groq
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
|
8 |
def icon(emoji: str):
|
@@ -13,12 +16,12 @@ def icon(emoji: str):
|
|
13 |
)
|
14 |
|
15 |
|
16 |
-
icon("
|
17 |
|
18 |
st.subheader("Groq Chat Streamlit App", divider="rainbow", anchor=False)
|
19 |
|
20 |
client = Groq(
|
21 |
-
api_key=
|
22 |
)
|
23 |
|
24 |
# Initialize chat history and selected model
|
@@ -71,7 +74,7 @@ with col2:
|
|
71 |
|
72 |
# Display chat messages from history on app rerun
|
73 |
for message in st.session_state.messages:
|
74 |
-
avatar = "π€" if message["role"] == "assistant" else "
|
75 |
with st.chat_message(message["role"], avatar=avatar):
|
76 |
st.markdown(message["content"])
|
77 |
|
@@ -86,7 +89,7 @@ def generate_chat_responses(chat_completion) -> Generator[str, None, None]:
|
|
86 |
if prompt := st.chat_input("Enter your prompt here..."):
|
87 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
88 |
|
89 |
-
with st.chat_message("user", avatar="
|
90 |
st.markdown(prompt)
|
91 |
|
92 |
# Fetch response from Groq API
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import find_dotenv, load_dotenv
|
3 |
import streamlit as st
|
4 |
from typing import Generator
|
5 |
from groq import Groq
|
6 |
|
7 |
+
_ = load_dotenv(find_dotenv())
|
8 |
+
st.set_page_config(page_icon="π¬", layout="wide", page_title="Groq Chat Bot...")
|
9 |
|
10 |
|
11 |
def icon(emoji: str):
|
|
|
16 |
)
|
17 |
|
18 |
|
19 |
+
icon("π£")
|
20 |
|
21 |
st.subheader("Groq Chat Streamlit App", divider="rainbow", anchor=False)
|
22 |
|
23 |
client = Groq(
|
24 |
+
api_key=os.environ['GROQ_API_KEY'],
|
25 |
)
|
26 |
|
27 |
# Initialize chat history and selected model
|
|
|
74 |
|
75 |
# Display chat messages from history on app rerun
|
76 |
for message in st.session_state.messages:
|
77 |
+
avatar = "π€" if message["role"] == "assistant" else "πΊ"
|
78 |
with st.chat_message(message["role"], avatar=avatar):
|
79 |
st.markdown(message["content"])
|
80 |
|
|
|
89 |
if prompt := st.chat_input("Enter your prompt here..."):
|
90 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
91 |
|
92 |
+
with st.chat_message("user", avatar="πΊ"):
|
93 |
st.markdown(prompt)
|
94 |
|
95 |
# Fetch response from Groq API
|