alihmaou commited on
Commit
1e051fc
·
verified ·
1 Parent(s): c9ca050

Delete tools/idfm_disruptions_v3.py

Browse files
Files changed (1) hide show
  1. tools/idfm_disruptions_v3.py +0 -61
tools/idfm_disruptions_v3.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- import json
3
- from PIL import Image
4
- import numpy as np
5
-
6
- # --- User Defined Logic ---
7
- import requests
8
- import json
9
- from typing import List, Dict, Any
10
-
11
- def idfm_disruptions_v3(mode: str, token: str, query: str = "") -> str:
12
- """Consult disruptions of Île-de-France transport via the PRIM API.
13
-
14
- Args:
15
- mode: Operation mode – "stats" for general statistics, "find" to search
16
- disruptions by a term, or "list" to return all disruptions.
17
- token: API key for the PRIM service (sent in the "apikey" header).
18
- query: Search term used only when mode is "find". Ignored otherwise.
19
-
20
- Returns:
21
- A string representation of the result.
22
- """
23
- url = "https://prim.iledefrance-mobilites.fr/marketplace/disruptions_bulk/disruptions/v2"
24
- headers = {"apikey": token}
25
-
26
- try:
27
- response = requests.get(url, headers=headers, timeout=10)
28
- response.raise_for_status()
29
- data: List[Dict[str, Any]] = response.json()
30
- except Exception as e:
31
- return json.dumps({"error": f"Échec de la requête API: {str(e)}"})
32
-
33
- if mode == "list":
34
- return json.dumps(data, ensure_ascii=False, indent=2)
35
-
36
- if mode == "find":
37
- if not query:
38
- return json.dumps({"error": "Query term is required for mode 'find'."})
39
- lowered = query.lower()
40
- filtered = [d for d in data if any(lowered in str(v).lower() for v in d.values())]
41
- return json.dumps(filtered, ensure_ascii=False, indent=2)
42
-
43
- if mode == "stats":
44
- total = len(data)
45
- result = {
46
- "total": total,
47
- "disruptions": data[:5] if len(data) > 5 else data
48
- }
49
- return json.dumps(result, ensure_ascii=False, indent=2)
50
-
51
- return json.dumps({"error": f"Unsupported mode: {mode}. Use 'stats', 'find' or 'list'."})
52
-
53
- # --- Interface Factory ---
54
- def create_interface():
55
- return gr.Interface(
56
- fn=idfm_disruptions_v3,
57
- inputs=[gr.Textbox(label=k) for k in ['mode', 'token', 'query']],
58
- outputs=gr.Textbox(label="Résultat JSON formaté contenant les perturbations selon le mode sélectionné"),
59
- title="idfm-disruptions-v3",
60
- description="Auto-generated tool: idfm-disruptions-v3"
61
- )