Spaces:
Sleeping
Sleeping
File size: 1,016 Bytes
edbe29c c0b0bef edbe29c c0b0bef ff3a4f9 c0b0bef edbe29c |
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 |
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()
|