# 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" | |
) | |