-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import streamlit as st | ||
from src.ui.streamlit_ui import TokenMyzerUI | ||
from src.api.groq_api import GroqAPI | ||
from config.config import load_config | ||
|
||
def main(): | ||
st.set_page_config(page_title="TokenMyzer", page_icon="🔤", layout="wide") | ||
|
||
config = load_config() | ||
api = GroqAPI(config) | ||
if 'api' not in st.session_state: | ||
st.session_state.api = GroqAPI() | ||
|
||
if not st.session_state.api.client or not st.session_state.get('api_key_valid', False): | ||
st.warning("Please enter a valid Groq API key to use the app.") | ||
st.session_state.api.initialize_client() | ||
|
||
if api.client: | ||
ui = TokenMyzerUI(api) | ||
if st.session_state.api.client and st.session_state.get('api_key_valid', False): | ||
ui = TokenMyzerUI(st.session_state.api) | ||
ui.run() | ||
else: | ||
st.error("Failed to initialize the Groq API client. Please check your API key and try again.") | ||
elif st.session_state.get('api_key_valid') == False: | ||
st.error("The provided API key is invalid. Please enter a valid Groq API key.") | ||
# Add a button to clear the invalid key | ||
if st.button("Clear API Key"): | ||
st.session_state.pop('groq_api_key', None) | ||
st.session_state.pop('api_key_valid', None) | ||
st.experimental_rerun() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters