Spaces:
Sleeping
Sleeping
Application File
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
import keyfile as kf
|
4 |
+
from langchain.llms import OpenAI
|
5 |
+
from langchain import PromptTemplate, LLMChain
|
6 |
+
|
7 |
+
# Set up the Streamlit app
|
8 |
+
st.title("Patient Symptom Analyzer")
|
9 |
+
|
10 |
+
# Input field for OpenAI API Key
|
11 |
+
api_key = kf.OPENKEY
|
12 |
+
|
13 |
+
# Check if API key is provided
|
14 |
+
if api_key:
|
15 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
16 |
+
|
17 |
+
# Initialize the OpenAI LLM
|
18 |
+
llm = OpenAI(temperature=0.7, max_tokens=1500)
|
19 |
+
|
20 |
+
# Input field for patient symptoms
|
21 |
+
symptoms = st.text_area("Enter the patient's symptoms:")
|
22 |
+
|
23 |
+
# Generate Report button
|
24 |
+
if st.button("Generate Report"):
|
25 |
+
if symptoms:
|
26 |
+
# Define the prompt template
|
27 |
+
prompt = PromptTemplate(
|
28 |
+
input_variables=["symptoms"],
|
29 |
+
template="""
|
30 |
+
Given the following patient symptoms: {symptoms},
|
31 |
+
provide general information including:
|
32 |
+
|
33 |
+
1. Common conditions associated with these symptoms (without making a diagnosis).
|
34 |
+
2. General advice on seeking professional medical help.
|
35 |
+
3. Preventive measures to maintain health.
|
36 |
+
|
37 |
+
Do not provide specific medical diagnoses or treatments. Emphasize the importance of consulting a healthcare professional for proper diagnosis and treatment.
|
38 |
+
"""
|
39 |
+
)
|
40 |
+
|
41 |
+
# Create the LLMChain with the prompt
|
42 |
+
chain = LLMChain(llm=llm, prompt=prompt)
|
43 |
+
|
44 |
+
# Generate the report
|
45 |
+
with st.spinner("Generating report..."):
|
46 |
+
try:
|
47 |
+
report = chain.run(symptoms)
|
48 |
+
st.success("Report generated successfully.")
|
49 |
+
st.write(report)
|
50 |
+
except Exception as e:
|
51 |
+
st.error(f"An error occurred: {e}")
|
52 |
+
else:
|
53 |
+
st.warning("Please enter the patient's symptoms.")
|
54 |
+
else:
|
55 |
+
st.warning("Please enter your OpenAI API Key.")
|