doctor / app.py
ahmadmac's picture
Update app.py
a95fb11 verified
raw
history blame
4.1 kB
# import streamlit as st
# from fpdf import FPDF
# import os
# llm_result = """
# Diagnosis: Pneumonia
# Prescription:
# - Amoxicillin 500 mg, twice daily for 7 days
# - Paracetamol 500 mg, every 6 hours for fever
# - Rest and hydration
# - Follow-up in 7 days if symptoms persist
# """
# def save_pdf(content):
# pdf = FPDF()
# pdf.add_page()
# pdf.set_font("Arial", size=12)
# pdf.multi_cell(0, 10, txt=content)
# pdf_output_path = "prescription.pdf"
# pdf.output(pdf_output_path)
# # Return the path to download
# return pdf_output_path
# # Streamlit app
# def main():
# st.title("Doctor's Assistance: Review and Edit Prescription")
# st.write("## Review the LLM-generated prescription and make edits if necessary.")
# edited_text = st.text_area("Edit Prescription", value=llm_result, height=300)
# if st.button("Save Prescription"):
# if edited_text.strip():
# pdf_file_path = save_pdf(edited_text)
# st.success("Prescription saved!")
# with open(pdf_file_path, "rb") as file:
# st.download_button(
# label="Download Prescription as PDF",
# data=file,
# file_name="prescription.pdf",
# mime="application/pdf"
# )
# else:
# st.error("Prescription content is empty. Please add details.")
# if __name__ == "__main__":
# main()
import streamlit as st
from fpdf import FPDF
import speech_recognition as sr
from io import BytesIO
# Function to predict disease based on symptoms
def predict_disease(symptoms):
# Example logic (replace with actual logic or model predictions)
if "fever" in symptoms.lower() and "cough" in symptoms.lower():
return "Flu"
elif "pain" in symptoms.lower() and "swelling" in symptoms.lower():
return "Arthritis"
else:
return "Unknown disease. Please provide more details."
# Function to handle voice input
def voice_input():
r = sr.Recognizer()
try:
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
st.write("Listening...")
audio = r.listen(source)
symptoms = r.recognize_google(audio)
return symptoms
except sr.UnknownValueError:
return "Sorry, I could not understand the audio."
except sr.RequestError:
return "Error with the speech recognition service."
except Exception as e:
return f"Microphone error: {e}"
# Function to save response to a PDF
def save_to_pdf(response):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.multi_cell(0, 10, f"Medical Assistant Response:\n\n{response}")
pdf_output = BytesIO()
pdf.output(pdf_output)
return pdf_output
# Streamlit app
st.title("Medical Assistance for Doctors")
st.write("Enter symptoms either by typing or using voice input.")
# Input field for entering symptoms manually
symptoms_input = st.text_area("Enter symptoms here:")
# Toggle for voice input
use_voice_input = st.checkbox("Use Voice Input")
# Checkbox to save the result as PDF
save_as_pdf = st.checkbox("Save result as PDF")
# Button to trigger prediction
if st.button("Submit"):
if use_voice_input:
symptoms = voice_input() # Get symptoms via voice input
if "error" in symptoms.lower():
st.error(symptoms) # Display the error message
else:
st.write(f"Symptoms recognized: {symptoms}")
else:
symptoms = symptoms_input # Use keyboard input
if symptoms:
prediction = predict_disease(symptoms) # Predict disease based on symptoms
st.write(f"Predicted Disease: {prediction}")
# Optionally save the response as a PDF
if save_as_pdf:
pdf_output = save_to_pdf(prediction)
st.download_button(
label="Download PDF",
data=pdf_output.getvalue(),
file_name="medical_assistance.pdf",
mime="application/pdf"
)