Skip to content

errorfound492/testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

testing

import google.generativeai as genai import streamlit as st from datetime import datetime

Configure Gemini API

genai.configure(api_key='AIzaSyAcL3sC72__d6z2dDck1T9STZRlrSJbJ9A') model = genai.GenerativeModel('gemini-1.5-flash')

Set up Streamlit page

st.set_page_config( page_title="Medical Assistant", page_icon="πŸ‘¨β€βš•οΈ", layout="wide" )

Add title and description

st.title("πŸ‘¨β€βš•οΈ AI Medical Assistant") st.write("Get medical information and advice powered by Gemini AI")

Disclaimer

st.warning("⚠️ This is an AI assistant and should not replace professional medical advice. For emergencies, contact your healthcare provider or call 911.")

Initialize chat history

if "messages" not in st.session_state: st.session_state.messages = []

Medical context prompt

medical_context = """ You are a helpful medical assistant AI. You can:

  1. Provide general medical information
  2. Explain medical terms
  3. Suggest healthy lifestyle tips
  4. Help understand symptoms
  5. Provide first aid information

Remember to:

  • Always recommend consulting a healthcare provider for specific medical advice
  • Never make definitive diagnoses
  • Be clear about limitations
  • Provide reliable, evidence-based information """

Function to get AI response

def get_medical_response(prompt): try: response = model.generate_content([medical_context, prompt]) return response.text except Exception as e: return f"Error: {str(e)}"

Chat interface

st.subheader("Medical Chat")

User input

user_input = st.text_input("Describe your medical question or concern:", key="user_input")

if st.button("Send"): if user_input: # Add user message to chat history st.session_state.messages.append({"role": "user", "content": user_input, "timestamp": datetime.now()})

    # Get AI response
    ai_response = get_medical_response(user_input)
    
    # Add AI response to chat history
    st.session_state.messages.append({"role": "assistant", "content": ai_response, "timestamp": datetime.now()})

Display chat history

for message in st.session_state.messages: if message["role"] == "user": st.write(f"πŸ‘€ You ({message['timestamp'].strftime('%H:%M')})") st.write(message["content"]) else: st.write(f"πŸ‘¨β€βš•οΈ Medical Assistant ({message['timestamp'].strftime('%H:%M')})") st.write(message["content"]) st.write("---")

Sidebar with quick access topics

st.sidebar.title("Quick Topics") quick_topics = [ "What are common cold symptoms?", "How to perform basic first aid?", "Tips for healthy sleep habits", "Understanding blood pressure readings", "Basic nutrition guidelines" ]

if st.sidebar.button("Clear Chat History"): st.session_state.messages = []

selected_topic = st.sidebar.selectbox("Select a topic:", quick_topics) if st.sidebar.button("Ask About Selected Topic"): # Add selected topic to chat st.session_state.messages.append({"role": "user", "content": selected_topic, "timestamp": datetime.now()}) ai_response = get_medical_response(selected_topic) st.session_state.messages.append({"role": "assistant", "content": ai_response, "timestamp": datetime.now()}) st.experimental_rerun()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published