File size: 3,925 Bytes
8b13f25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a95fb11
 
121e6d4
f59e0ec
 
121e6d4
59c8cf4
f59e0ec
b1cffd1
f59e0ec
 
 
 
 
 
 
 
 
 
 
 
 
 
b1cffd1
 
59c8cf4
b1cffd1
 
59c8cf4
b1cffd1
 
121e6d4
 
 
b1cffd1
 
 
f59e0ec
59c8cf4
b1cffd1
59c8cf4
8b13f25
59c8cf4
df77779
59c8cf4
8b13f25
59c8cf4
 
df77779
59c8cf4
 
df77779
59c8cf4
 
6be36f9
59c8cf4
 
 
 
 
 
df77779
59c8cf4
 
 
121e6d4
59c8cf4
 
b1cffd1
df77779
59c8cf4
 
 
df77779
 
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
# 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
import speech_recognition as sr
from io import BytesIO
from fpdf import FPDF

# Function to handle voice input using speech_recognition
def voice_input():
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        st.write("Listening...")
        audio = recognizer.listen(source)
        try:
            text = recognizer.recognize_google(audio)
            st.write(f"Recognized: {text}")
            return text
        except sr.UnknownValueError:
            st.write("Google Speech Recognition could not understand the audio")
            return ""
        except sr.RequestError as e:
            st.write(f"Could not request results from Google Speech Recognition service; {e}")
            return ""

# Function to simulate disease prediction
def predict_disease(symptoms):
    # Placeholder function for predicting disease based on symptoms
    return "Disease based on symptoms: Placeholder prediction"

# Function to save results as a PDF
def save_to_pdf(content):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=12)
    pdf.cell(200, 10, txt="Medical Assistance Results", ln=True, align='C')
    pdf.ln(10)
    pdf.multi_cell(0, 10, content)
    pdf_output = BytesIO()
    pdf.output(pdf_output)
    pdf_output.seek(0)
    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
    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(f"Symptoms: {symptoms}\n\nPrediction: {prediction}")
            st.download_button(
                label="Download PDF",
                data=pdf_output.getvalue(),
                file_name="medical_assistance.pdf",
                mime="application/pdf"
            )