import streamlit as st from openai import OpenAI import time import os import logging from groq import Groq import os import streamlit as st import logging from groq import Groq # Logging setup logging.basicConfig(level=logging.INFO) # Streamlit page configuration st.set_page_config( page_title="Gazal.ai-o1-preview", page_icon="🦌", layout="centered" ) # Improved CSS for better contrast and design st.markdown("""

Disclaimer

This app is for demonstration purposes only. The purpose of this demo is to showcase the power of reasoning large language models (LLMs) in guiding clinical decision support systems. It is not intended for clinical use. Please consult medical professionals for accurate medical advice.

""", unsafe_allow_html=True) # Groq API client initialization @st.cache_resource def init_groq_client(): return Groq(api_key=os.getenv("GROQ_API_KEY")) # Chat with Groq model def chat_with_groq(client, message, history): try: # Build the conversation context messages = [ {"role": "system", "content": "You are a helpful medical and clinical decision support system. Think step by step before answering."}, *[{"role": "user" if i % 2 == 0 else "assistant", "content": m} for h in history for i, m in enumerate(h)], {"role": "user", "content": message} ] # Call the Groq model completion = client.chat.completions.create( model="deepseek-r1-distill-llama-70b", messages=messages, temperature=0.6, max_tokens=4000, top_p=0.95, stream=True, # Stream the response ) # Stream the response chunk by chunk response = "" for chunk in completion: content = chunk.choices[0].delta.content or "" response += content yield response except Exception as e: logging.error(f"Error during Groq inference: {str(e)}") yield f"An error occurred: {str(e)}. Please check your API key and network connection." # Initialize app state if "history" not in st.session_state: st.session_state["history"] = [] # [(user_message, bot_response), ...] # Display the app title and description st.title("Gazal.ai-o1-preview 🦌") st.write("Ask gazal.ai any healthcare question and it will provide step-by-step reasoning.") # Input form with st.form("chat_form", clear_on_submit=True): user_message = st.text_input("Your Message:", key="user_input") submitted = st.form_submit_button("Send") # Process user input and display chat if submitted and user_message: # Add user message to history st.session_state["history"].append((user_message, None)) # Display chat history for user_text, bot_text in st.session_state["history"]: st.markdown(f'
{user_text}
', unsafe_allow_html=True) if bot_text: st.markdown(f'
{bot_text}
', unsafe_allow_html=True) # Initialize Groq client groq_client = init_groq_client() # Generate bot response response_placeholder = st.empty() # Placeholder for streaming updates bot_response = "" for partial_response in chat_with_groq(groq_client, user_message, st.session_state["history"][:-1]): bot_response = partial_response # Update bot response incrementally response_placeholder.markdown(f'
{bot_response}
', unsafe_allow_html=True) # Update history with full bot response st.session_state["history"][-1] = (user_message, bot_response) # Clear chat history button # Clear chat history button if st.button("Clear Chat"): st.session_state["history"] = [] st.rerun() # Footer st.markdown('', unsafe_allow_html=True)