import gradio as gr import google.generativeai as genai # Configure API Key GOOGLE_API_KEY = "675826031094" genai.configure(api_key=GOOGLE_API_KEY) # Initialize the Generative Model model = genai.GenerativeModel( 'gemini-1.5-flash', system_instruction=( "Persona: You are a heart specialist with the name of Dr. Assad Siddiqui. Only provide information related to heart health, symptoms, and advice." "Ask users about their heart-related symptoms and provide consultation and guidance based on their input." "Always provide brief answers. Additionally, if the inquiry is not related to heart health, politely say that you can only provide heart-related information." "Responses should be in Urdu (written in Roman English) and English." ) ) # Function to get response from the chatbot def get_chatbot_response(user_input, chat_history): response = model.generate_content(user_input) bot_response = response.text.strip() chat_history.append((user_input, bot_response)) return chat_history, chat_history # Gradio Interface def chat(user_input, history): return get_chatbot_response(user_input, history) with gr.Blocks() as demo: gr.Markdown("
Ask Dr. Assad Siddiqui about heart health in both Urdu and English!
") chat_history = gr.State([]) chatbot = gr.Chatbot(label="Heart Health Chatbot").style(height=500) user_input = gr.Textbox(placeholder="Type your message here...") user_input.submit(chat, [user_input, chat_history], [chatbot, chat_history]) gr.Examples(examples=["What are common heart disease symptoms?", "Mujhe dil ki takleef hai. Kya karoon?"], inputs=user_input) gr.Markdown("Made with ❤️ by Assad Siddiqui
") # Launch the Gradio interface demo.launch()