import gradio as gr from main import extract_entities_from_file from starlette.requests import ClientDisconnect def process(file): try: file_path = file.name # Extract the temp file path from NamedString results = extract_entities_from_file(file_path) if not results: return "No entities found." return "\n".join([f"{text} -> {label}" for text, label in results]) except ClientDisconnect: print("Client disconnected during processing.") return "Client disconnected before processing could complete." except Exception as e: print(f"Unhandled error: {e}") return "An error occurred during processing." iface = gr.Interface( fn=process, inputs=gr.File(label="Upload a text file"), outputs=gr.Textbox(label="Extracted Entities"), title="GLiNER + SpaCy Entity Extractor", description="Upload a text file to extract PERSON, ORG, LOCATION, and DISEASE entities." ) if __name__ == "__main__": iface.launch()