File size: 1,830 Bytes
53f4863
 
 
1d211eb
53f4863
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import streamlit as st
import keyfile as kf
import langchain
from langchain.llms import OpenAI
from langchain import PromptTemplate, LLMChain

# Set up the Streamlit app
st.title("Patient Symptom Analyzer")

# Input field for OpenAI API Key
api_key = kf.OPENKEY

# Check if API key is provided
if api_key:
    os.environ["OPENAI_API_KEY"] = api_key
    
    # Initialize the OpenAI LLM
    llm = OpenAI(temperature=0.7, max_tokens=1500)

    # Input field for patient symptoms
    symptoms = st.text_area("Enter the patient's symptoms:")

    # Generate Report button
    if st.button("Generate Report"):
        if symptoms:
            # Define the prompt template
            prompt = PromptTemplate(
                input_variables=["symptoms"],
                template="""
Given the following patient symptoms: {symptoms},
provide general information including:

1. Common conditions associated with these symptoms (without making a diagnosis).
2. General advice on seeking professional medical help.
3. Preventive measures to maintain health.

Do not provide specific medical diagnoses or treatments. Emphasize the importance of consulting a healthcare professional for proper diagnosis and treatment.
"""
            )

            # Create the LLMChain with the prompt
            chain = LLMChain(llm=llm, prompt=prompt)

            # Generate the report
            with st.spinner("Generating report..."):
                try:
                    report = chain.run(symptoms)
                    st.success("Report generated successfully.")
                    st.write(report)
                except Exception as e:
                    st.error(f"An error occurred: {e}")
        else:
            st.warning("Please enter the patient's symptoms.")
else:
    st.warning("Please enter your OpenAI API Key.")