Update app.py
Browse files
app.py
CHANGED
@@ -50,45 +50,46 @@
|
|
50 |
|
51 |
|
52 |
import streamlit as st
|
|
|
|
|
|
|
|
|
53 |
from fpdf import FPDF
|
54 |
-
import speech_recognition as sr
|
55 |
-
from io import BytesIO
|
56 |
|
57 |
-
# Function to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def predict_disease(symptoms):
|
59 |
-
#
|
60 |
-
|
61 |
-
return "Flu"
|
62 |
-
elif "pain" in symptoms.lower() and "swelling" in symptoms.lower():
|
63 |
-
return "Arthritis"
|
64 |
-
else:
|
65 |
-
return "Unknown disease. Please provide more details."
|
66 |
|
67 |
-
# Function to
|
68 |
-
def
|
69 |
-
r = sr.Recognizer()
|
70 |
-
try:
|
71 |
-
with sr.Microphone() as source:
|
72 |
-
r.adjust_for_ambient_noise(source)
|
73 |
-
st.write("Listening...")
|
74 |
-
audio = r.listen(source)
|
75 |
-
symptoms = r.recognize_google(audio)
|
76 |
-
return symptoms
|
77 |
-
except sr.UnknownValueError:
|
78 |
-
return "Sorry, I could not understand the audio."
|
79 |
-
except sr.RequestError:
|
80 |
-
return "Error with the speech recognition service."
|
81 |
-
except Exception as e:
|
82 |
-
return f"Microphone error: {e}"
|
83 |
-
|
84 |
-
# Function to save response to a PDF
|
85 |
-
def save_to_pdf(response):
|
86 |
pdf = FPDF()
|
87 |
pdf.add_page()
|
88 |
pdf.set_font("Arial", size=12)
|
89 |
-
pdf.
|
90 |
-
|
|
|
|
|
91 |
pdf.output(pdf_output)
|
|
|
92 |
return pdf_output
|
93 |
|
94 |
# Streamlit app
|
@@ -108,10 +109,7 @@ save_as_pdf = st.checkbox("Save result as PDF")
|
|
108 |
if st.button("Submit"):
|
109 |
if use_voice_input:
|
110 |
symptoms = voice_input() # Get symptoms via voice input
|
111 |
-
|
112 |
-
st.error(symptoms) # Display the error message
|
113 |
-
else:
|
114 |
-
st.write(f"Symptoms recognized: {symptoms}")
|
115 |
else:
|
116 |
symptoms = symptoms_input # Use keyboard input
|
117 |
|
@@ -121,7 +119,7 @@ if st.button("Submit"):
|
|
121 |
|
122 |
# Optionally save the response as a PDF
|
123 |
if save_as_pdf:
|
124 |
-
pdf_output = save_to_pdf(prediction)
|
125 |
st.download_button(
|
126 |
label="Download PDF",
|
127 |
data=pdf_output.getvalue(),
|
|
|
50 |
|
51 |
|
52 |
import streamlit as st
|
53 |
+
import sounddevice as sd
|
54 |
+
import numpy as np
|
55 |
+
import io
|
56 |
+
import wavio
|
57 |
from fpdf import FPDF
|
|
|
|
|
58 |
|
59 |
+
# Function to handle voice input using sounddevice
|
60 |
+
def voice_input():
|
61 |
+
st.write("Listening...")
|
62 |
+
fs = 44100 # Sample rate
|
63 |
+
duration = 5 # Duration in seconds
|
64 |
+
|
65 |
+
# Record audio
|
66 |
+
audio_data = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
|
67 |
+
sd.wait() # Wait until recording is finished
|
68 |
+
|
69 |
+
# Save to a WAV file
|
70 |
+
wav_buffer = io.BytesIO()
|
71 |
+
wavio.write(wav_buffer, audio_data, fs, sampwidth=2)
|
72 |
+
wav_buffer.seek(0)
|
73 |
+
|
74 |
+
# Convert audio to text (placeholder, you need to use a library/service for actual transcription)
|
75 |
+
return "Symptoms recognized: Placeholder text from audio"
|
76 |
+
|
77 |
+
# Function to simulate disease prediction
|
78 |
def predict_disease(symptoms):
|
79 |
+
# Placeholder function for predicting disease based on symptoms
|
80 |
+
return "Disease based on symptoms: Placeholder prediction"
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
# Function to save results as a PDF
|
83 |
+
def save_to_pdf(content):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
pdf = FPDF()
|
85 |
pdf.add_page()
|
86 |
pdf.set_font("Arial", size=12)
|
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 = io.BytesIO()
|
91 |
pdf.output(pdf_output)
|
92 |
+
pdf_output.seek(0)
|
93 |
return pdf_output
|
94 |
|
95 |
# Streamlit app
|
|
|
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 |
|
|
|
119 |
|
120 |
# Optionally save the response as a PDF
|
121 |
if save_as_pdf:
|
122 |
+
pdf_output = save_to_pdf(f"Symptoms: {symptoms}\n\nPrediction: {prediction}")
|
123 |
st.download_button(
|
124 |
label="Download PDF",
|
125 |
data=pdf_output.getvalue(),
|