Update app.py
Browse files
app.py
CHANGED
@@ -50,29 +50,26 @@
|
|
50 |
|
51 |
|
52 |
import streamlit as st
|
53 |
-
import
|
54 |
-
|
55 |
-
import io
|
56 |
-
import wavio
|
57 |
from fpdf import FPDF
|
58 |
|
59 |
-
# Function to handle voice input using
|
60 |
def voice_input():
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
return "Symptoms recognized: Placeholder text from audio"
|
76 |
|
77 |
# Function to simulate disease prediction
|
78 |
def predict_disease(symptoms):
|
@@ -87,7 +84,7 @@ def save_to_pdf(content):
|
|
87 |
pdf.cell(200, 10, txt="Medical Assistance Results", ln=True, align='C')
|
88 |
pdf.ln(10)
|
89 |
pdf.multi_cell(0, 10, content)
|
90 |
-
pdf_output =
|
91 |
pdf.output(pdf_output)
|
92 |
pdf_output.seek(0)
|
93 |
return pdf_output
|
@@ -109,7 +106,6 @@ save_as_pdf = st.checkbox("Save result as PDF")
|
|
109 |
if st.button("Submit"):
|
110 |
if use_voice_input:
|
111 |
symptoms = voice_input() # Get symptoms via voice input
|
112 |
-
st.write(f"Symptoms recognized: {symptoms}")
|
113 |
else:
|
114 |
symptoms = symptoms_input # Use keyboard input
|
115 |
|
@@ -126,4 +122,3 @@ if st.button("Submit"):
|
|
126 |
file_name="medical_assistance.pdf",
|
127 |
mime="application/pdf"
|
128 |
)
|
129 |
-
|
|
|
50 |
|
51 |
|
52 |
import streamlit as st
|
53 |
+
import speech_recognition as sr
|
54 |
+
from io import BytesIO
|
|
|
|
|
55 |
from fpdf import FPDF
|
56 |
|
57 |
+
# Function to handle voice input using speech_recognition
|
58 |
def voice_input():
|
59 |
+
recognizer = sr.Recognizer()
|
60 |
+
with sr.Microphone() as source:
|
61 |
+
st.write("Listening...")
|
62 |
+
audio = recognizer.listen(source)
|
63 |
+
try:
|
64 |
+
text = recognizer.recognize_google(audio)
|
65 |
+
st.write(f"Recognized: {text}")
|
66 |
+
return text
|
67 |
+
except sr.UnknownValueError:
|
68 |
+
st.write("Google Speech Recognition could not understand the audio")
|
69 |
+
return ""
|
70 |
+
except sr.RequestError as e:
|
71 |
+
st.write(f"Could not request results from Google Speech Recognition service; {e}")
|
72 |
+
return ""
|
|
|
73 |
|
74 |
# Function to simulate disease prediction
|
75 |
def predict_disease(symptoms):
|
|
|
84 |
pdf.cell(200, 10, txt="Medical Assistance Results", ln=True, align='C')
|
85 |
pdf.ln(10)
|
86 |
pdf.multi_cell(0, 10, content)
|
87 |
+
pdf_output = BytesIO()
|
88 |
pdf.output(pdf_output)
|
89 |
pdf_output.seek(0)
|
90 |
return pdf_output
|
|
|
106 |
if st.button("Submit"):
|
107 |
if use_voice_input:
|
108 |
symptoms = voice_input() # Get symptoms via voice input
|
|
|
109 |
else:
|
110 |
symptoms = symptoms_input # Use keyboard input
|
111 |
|
|
|
122 |
file_name="medical_assistance.pdf",
|
123 |
mime="application/pdf"
|
124 |
)
|
|