Migjomatic commited on
Commit
2aab908
·
1 Parent(s): 7995d4a
Files changed (1) hide show
  1. README.md +181 -42
README.md CHANGED
@@ -1,69 +1,208 @@
1
- # Video Frame Analyzer with Hugging Face
2
 
3
- A Streamlit application that extracts frames from videos and analyzes them using Hugging Face vision-language models.
 
 
4
 
5
- ## Features
 
6
 
7
- - Upload video files (MP4, AVI, MOV, MKV)
8
- - Extract frames at configurable intervals (fps)
9
- - Analyze each frame using various Hugging Face models
10
- - Custom prompt input for frame analysis
11
- - Real-time results display
12
 
13
- ## Setup
14
 
15
- 1. Create a Python virtual environment:
16
- ```bash
17
- python -m venv venv
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  ```
19
 
20
- 2. Activate the virtual environment:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  ```bash
22
- # On Windows
 
23
  venv\Scripts\activate
24
-
25
- # On macOS/Linux
26
  source venv/bin/activate
27
- ```
28
 
29
- 3. Upgrade pip and install setuptools:
30
- ```bash
31
  python -m pip install --upgrade pip setuptools wheel
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  ```
33
 
34
- 4. Install dependencies:
 
35
  ```bash
36
- pip install -r requirements.txt
37
  ```
38
 
39
- 5. Get a Hugging Face API token:
40
- - Visit https://huggingface.co/settings/tokens
41
- - Create a new token
42
 
43
- 6. Run the application:
44
  ```bash
45
  streamlit run app.py
46
  ```
47
 
48
- ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- 1. Enter your Hugging Face API token in the sidebar
51
- 2. Select a vision-language model
52
- 3. Upload a video file
53
- 4. Enter your analysis prompt
54
- 5. Adjust frame extraction rate if needed
55
- 6. Click "Process Video"
56
 
57
- ## Available Models
58
 
59
- - Kosmos-2: General vision-language understanding
60
- - BLIP Image Captioning: Image captioning and description
61
- - GIT Large COCO: Visual question answering
62
- - ViT-GPT2: Image to text generation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
- ## Example Prompts
65
 
66
- - "Describe what you see in this image"
67
- - "Count the number of people in this scene"
68
- - "What objects are visible in this frame?"
69
- - "Describe the emotions of people in this image"
 
1
+ # 🚆 Bahngleiserfassung – Video Frame Analyzer (Streamlit + HF + Ontologie)
2
 
3
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](#)
4
+ [![Streamlit](https://img.shields.io/badge/Streamlit-App-red.svg)](#)
5
+ [![Status](https://img.shields.io/badge/Build-ok-brightgreen.svg)](#)
6
 
7
+ Kurzerklärung: Dieses Projekt extrahiert Videoframes (Bahnsteigkamera) und bewertet die Szene **ontologie-basiert** – z. B. „**Person befindet sich im Gleis**“ ⇒ **kritische** Meldung.
8
+ Die Bewertung ist **erklärbar** (Regeln + RDF-artige Tripel).
9
 
10
+ > 📘 **Detailseite (Extra-Tab):** [Ontologie & Regeln Deep Dive](docs/ONTOLOGIE.md)
 
 
 
 
11
 
12
+ ---
13
 
14
+ ## 🧭 Inhalt
15
+ - [✨ Features](#-features)
16
+ - [🏗️ Projektstruktur](#️-projektstruktur)
17
+ - [🚀 Schnellstart](#-schnellstart)
18
+ - [⚙️ Konfiguration](#️-konfiguration)
19
+ - [🖥️ Nutzung](#️-nutzung)
20
+ - [🧠 Was ist eine Ontologie?](#-was-ist-eine-ontologie)
21
+ - [🧪 Tests & Tripel-Export](#-tests--tripel-export)
22
+ - [🛡️ Sicherheit (Secrets)](#️-sicherheit-secrets)
23
+ - [🧰 Troubleshooting](#-troubleshooting)
24
+ - [📄 Lizenz](#-lizenz)
25
+
26
+ ---
27
+
28
+ ## ✨ Features
29
+ - 📼 **Video-Upload** (MP4/AVI/MOV/MKV), auto-Frame-Extraktion
30
+ - 🤖 **HF-Modelle** (Vision/Language) zur Szeneninterpretation
31
+ - 🧩 **Ontologie-Bewertung** (Regeln wie `befindetSichIn(Gleis)`)
32
+ - 🧾 **Erklärungen** (welche Regeln ausgelöst haben)
33
+ - 🧷 **Tripel-Export** (Turtle-ähnlich) zur Weiterverarbeitung
34
+
35
+ ---
36
+
37
+ ## 🏗️ Projektstruktur
38
  ```
39
 
40
+ .
41
+ ├─ app.py # Streamlit-App (UI ohne Freitext-Prompts)
42
+ ├─ ontology\_eval.py # Regeln + Ontologie-Tripel-Export
43
+ ├─ test\_ontology\_triples.py # Mini-Test + Turtle-Ausgabe
44
+ ├─ detect\_person\_on\_tracks.py # Beispiel-Analyse (einbinden/erweitern)
45
+ ├─ requirements.txt
46
+ ├─ settings.json.example
47
+ ├─ .env.example
48
+ └─ docs/
49
+ └─ ONTOLOGIE.md # Detaildoku (Extra-Tab)
50
+
51
+ ````
52
+
53
+ ---
54
+
55
+ ## 🚀 Schnellstart
56
  ```bash
57
+ python -m venv venv
58
+ # Windows:
59
  venv\Scripts\activate
60
+ # macOS/Linux:
 
61
  source venv/bin/activate
 
62
 
 
 
63
  python -m pip install --upgrade pip setuptools wheel
64
+ pip install -r requirements.txt
65
+ ````
66
+
67
+ ---
68
+
69
+ ## ⚙️ Konfiguration
70
+
71
+ **Hugging Face Token** (nicht committen):
72
+
73
+ ```powershell
74
+ # Windows (Session)
75
+ $env:HF_TOKEN="hf_xxx_dein_token"
76
+ # Optional dauerhaft:
77
+ setx HF_TOKEN "hf_xxx_dein_token"
78
  ```
79
 
80
+ Optionale App-Settings:
81
+
82
  ```bash
83
+ cp settings.json.example settings.json
84
  ```
85
 
86
+ ---
87
+
88
+ ## 🖥️ Nutzung
89
 
 
90
  ```bash
91
  streamlit run app.py
92
  ```
93
 
94
+ * 📤 Video hochladen → **Analyse startet automatisch** (keine Freitext-Prompts).
95
+ * 🧯 Ergebnis als **Meldung** mit Icon:
96
+
97
+ * ✅ NONE / 🟢 LOW / 🟠 MEDIUM / ⚠️ HIGH / 🚨 CRITICAL
98
+ * 🔗 Button „Details im neuen Fenster“ öffnet die Ergebnisansicht in **neuem Tab**.
99
+
100
+ ---
101
+
102
+ ## 🧠 Was ist eine Ontologie?
103
+
104
+ Eine **Ontologie** beschreibt die Domäne formal (Klassen/Beziehungen/Eigenschaften), z. B.:
105
+
106
+ * **Klassen:** `Person`, `Gleis`, `Bahnsteig`, `Zug`, `Gefahr`, `Sensor`, `Videoüberwachung`, `Alarmsystem`, `Maßnahme`, `Ereignis`, `Objekt`
107
+ * **Objekt-Properties:** `befindetSichIn`, `erkennt`, `stehtAuf`, `beobachtet`, `überwacht`, `löstAus`, `führtZu`, `meldet`
108
+ * **Daten-Properties:** `hatKonfidenz (xsd:float)`, `hatZeitstempel (xsd:dateTime)`, `hatPosition (xsd:string)`, `hatBeschreibung (xsd:string)`
109
+
110
+ So wird aus ML-Signalen **bedeutungsvolle** Logik:
111
+ „Person im Gleis“ ⇒ **Gefahr** ⇒ **Alarm** ⇒ **Maßnahme**.
112
+
113
+ > 🔎 Mehr Details inkl. Regeln (R1–R6) und Turtle-Beispielen:
114
+ > **[docs/ONTOLOGIE.md](docs/ONTOLOGIE.md)**
115
+
116
+ ---
117
+
118
+ ## 🧪 Tests & Tripel-Export
119
+
120
+ Schneller Test der Bewertung & Tripel:
121
+
122
+ ```bash
123
+ python test_ontology_triples.py
124
+ ```
125
+
126
+ Ausgabe: Severity/Score/Labels/Erklärungen + Turtle-Tripel.
127
+
128
+ ---
129
+
130
+ ## 🛡️ Sicherheit (Secrets)
131
+
132
+ * **Keine** Tokens/Passwörter in Code/Repo einchecken.
133
+ * `.env` ist ignoriert (`.gitignore`).
134
+ * Bei Leak: **Token sofort revoken/rotieren** (HF-Settings).
135
+
136
+ ---
137
+
138
+ ## 🧰 Troubleshooting
139
+
140
+ * ❗ **Kein HF\_TOKEN gefunden** → Token setzen (s. o.).
141
+ * 🧩 **FFmpeg fehlt** → installieren und zum `PATH` hinzufügen (für robuste Video-Extraktion).
142
+ * 🔁 **Zeilenende-Warnungen (CRLF/LF)** → harmlos; ggf. `git config --global core.autocrlf true`.
143
+
144
+ ---
145
 
146
+ ## 📄 Lizenz
 
 
 
 
 
147
 
148
+ tbd (z. B. MIT)
149
 
150
+ ````
151
+
152
+ ---
153
+
154
+ ### `docs/ONTOLOGIE.md`
155
+
156
+ ```markdown
157
+ # 📘 Ontologie & Regeln – Deep Dive
158
+
159
+ Diese Seite beschreibt die Ontologie, das Regelwerk und die erzeugten Tripel.
160
+
161
+ ## 🧠 Ontologie (Auszug)
162
+ **Klassen:** `Person`, `Gleis`, `Bahnsteig`, `Zug`, `Gefahr`, `Sensor`, `Videoüberwachung`, `Alarmsystem`, `Maßnahme`, `Ereignis`, `Objekt`
163
+ **Objekt-Properties:** `befindetSichIn`, `erkennt`, `überwacht`, `beobachtet`, `stehtAuf`, `löstAus`, `führtZu`, `meldet`
164
+ **Daten-Properties:** `hatKonfidenz (xsd:float)`, `hatZeitstempel (xsd:dateTime)`, `hatPosition (xsd:string)`, `hatBeschreibung (xsd:string)`
165
+
166
+ ## ⚖️ Bewertungslogik (R1–R6)
167
+ - **R1 – Person im Gleis** → `CRITICAL`
168
+ `on_track_person ≥ Schwelle` ⇒ Tripel: `ex:person ex:befindetSichIn ex:gleis`
169
+ - **R2 – Nahe Kante + Zug** → `HIGH`
170
+ `distance_to_edge ≤ 0.5m` ∧ `train_approaching ≥ Schwelle`
171
+ - **R3 – Gestürzte Person nahe Kante/auf Gleis** → `HIGH/CRITICAL`
172
+ - **R4 – Objekt im Gleis** → `MEDIUM`
173
+ - **R5 – Rauch/Feuer** → `HIGH`
174
+ - **R6 – Menschenmenge im Gleisbereich** → `CRITICAL`
175
+
176
+ **Recall-Bias:** Standard-Schwelle `0.35` (Sicherheitsdomäne → lieber einmal zu viel melden).
177
+
178
+ ## 🧾 Tripel-Export (Turtle-ähnlich)
179
+ Beispielauszug:
180
+ ```turtle
181
+ ex:person42 rdf:type ex:Person .
182
+ ex:gleis_3 rdf:type ex:Gleis .
183
+ ex:person42 ex:befindetSichIn ex:gleis_3 .
184
+ ex:gef1 rdf:type ex:Gefahr .
185
+ ex:gef1 ex:löstAus ex:alarm_4711 .
186
+ ex:alarm_4711 ex:führtZu ex:massnahme_stop .
187
+ ex:event_utc ex:hatZeitstempel "2025-09-06T14:32:10Z"^^xsd:dateTime .
188
+ ````
189
+
190
+ ## 🔌 Integration
191
+
192
+ Im Code (Beispiel):
193
+
194
+ ```python
195
+ from ontology_eval import Observation, evaluate, OntologyContext, decision_to_triples, triples_to_turtle
196
+
197
+ obs = Observation(on_track_person=0.88, distance_to_edge_m=0.3, train_approaching=0.9)
198
+ dec = evaluate(obs)
199
+
200
+ ctx = OntologyContext(person_id="person42", track_id="gleis_3", platform_id="bahnsteig_3")
201
+ print(triples_to_turtle(decision_to_triples(dec, obs, ctx)))
202
+ ```
203
 
204
+ ## 🧩 Erweiterung
205
 
206
+ * Neue Klassen/Properties ergänzen (z. B. `Kinderwagen`, `Warnweste`)
207
+ * Weitere Regeln (z. B. „Sperrbereich aktiv“ höhere Schwere)
208
+ * Export als **TTL/JSON-LD/CSV** für Downstream-Systeme