Spaces:
Paused
Paused
File size: 2,557 Bytes
5be262b | 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 | import gradio as gr
import os
from .app import agents
import tempfile
import logging
logging.basicConfig(level=logging.INFO)
def process_document(file, process_type):
try:
# Create a temporary file to store the upload
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file.name)[1]) as temp_file:
temp_file.write(file.read())
temp_path = temp_file.name
results = {}
if process_type == "text_extraction":
results["extracted_text"] = agents["text_extractor"].extract_text(temp_path)
results["phi_scrubbed"] = agents["phi_scrubber"].scrub_phi(results["extracted_text"])
elif process_type == "medical_data":
text = agents["text_extractor"].extract_text(temp_path)
results["medical_data"] = agents["medical_data_extractor"].extract_medical_data(text)
elif process_type == "summarization":
text = agents["text_extractor"].extract_text(temp_path)
results["summary"] = agents["summarizer"].summarize(text)
elif process_type == "audio_transcription":
results["transcription"] = agents["whisper_model"].transcribe(temp_path)
# Clean up temporary file
os.unlink(temp_path)
return results
except Exception as e:
logging.error(f"Error processing document: {str(e)}", exc_info=True)
return {"error": str(e)}
# Create the Gradio interface
def create_interface():
with gr.Blocks(title="Medical Document Processor") as interface:
gr.Markdown("# Medical Document Processor")
gr.Markdown("Upload your medical document and select the processing type.")
with gr.Row():
with gr.Column():
file_input = gr.File(label="Upload Document")
process_type = gr.Radio(
choices=["text_extraction", "medical_data", "summarization", "audio_transcription"],
label="Processing Type"
)
process_btn = gr.Button("Process Document")
with gr.Column():
output = gr.JSON(label="Results")
process_btn.click(
fn=process_document,
inputs=[file_input, process_type],
outputs=output
)
return interface
# Create and launch the interface
interface = create_interface()
interface.launch(server_name="0.0.0.0", server_port=7860) |