File size: 4,097 Bytes
8b13f25 a95fb11 121e6d4 59c8cf4 df77779 59c8cf4 df77779 59c8cf4 df77779 59c8cf4 df77779 59c8cf4 121e6d4 59c8cf4 8b13f25 59c8cf4 df77779 59c8cf4 8b13f25 59c8cf4 df77779 59c8cf4 df77779 59c8cf4 6be36f9 59c8cf4 df77779 59c8cf4 121e6d4 59c8cf4 df77779 59c8cf4 df77779 a95fb11 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# 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"
)
|