Spaces:
Sleeping
Sleeping
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.") |