"""Text extraction demo: turns a claimant story or police report into structured incident fields. The model runs on Groq, so this Space needs no GPU. Set the secret GROQ_API_KEY and the variable GROQ_MODEL (for example openai/gpt-oss-20b) in the Space settings. """ import gradio as gr import spaces from incident_extraction.extraction import ExtractionError, extract_incident @spaces.GPU(duration=1) def _zerogpu_placeholder(): """Never called. ZeroGPU Spaces must declare one GPU function to start.""" pass def analyse(text, source): if not text or not text.strip(): raise gr.Error("Paste a claimant story or police report first.") try: incident = extract_incident(text) except ExtractionError as error: raise gr.Error(str(error)) return {"source": source, "incident": incident.model_dump()} demo = gr.Interface( fn=analyse, inputs=[gr.Textbox(label="Document text", lines=8), gr.Radio(["claimant", "police"], value="claimant", label="Source")], outputs=gr.JSON(label="Extracted fields"), title="Incident text extraction", description="Extracts date, time, location, vehicles, fault, incident type and impacts. " "Facts the text doesn't state stay empty.", api_name="predict", flagging_mode="never", ) if __name__ == "__main__": demo.launch()