import os import streamlit as st from groq import Groq # Replace with your actual Groq API key api_key = "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" # Alternatively, set the key using environment variable client = Groq(api_key=api_key) # Initialize a chat model using Groq's API def generate_response(prompt): try: chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": prompt}], model="llama3-8b-8192", # You can adjust the model to your choice ) return chat_completion.choices[0].message.content except Exception as e: return f"Error: {str(e)}" # Handle multi-language support def get_chatbot_response(user_input, language='en'): if language == 'en': return generate_response(user_input) else: # Translate input to English if it's not in English translated_input = translate_to_english(user_input, language) response = generate_response(translated_input) return translate_from_english(response, language) def translate_to_english(text, lang): # Placeholder function to translate input text to English if necessary # Here, you could integrate with Google Translate API or similar. # For now, just return the text as-is. # You can use the `lang` parameter to apply different translation logic if needed. return text def translate_from_english(text, lang): # Placeholder function to translate the response back to the target language # Here, you could integrate with Google Translate API or similar. # For now, just return the text as-is. return text # Streamlit frontend def main(): st.title("Healthcare Assistant Chatbot") st.write("Get medical advice, medication suggestions, and personalized diet/exercise tips.") # Language selection language = st.selectbox("Select Language", ['en', 'es', 'fr', 'de', 'hi', 'ur', 'bn', 'ar']) user_input = st.text_input("Ask a question related to healthcare:") if st.button("Submit"): if user_input: response = get_chatbot_response(user_input, language) st.write("Response: ", response) else: st.write("Please enter a valid question.") if __name__ == "__main__": main()