mboushaba commited on
Commit
dac704b
1 Parent(s): 7a72f44

first commit - init

Browse files
Files changed (2) hide show
  1. app.py +72 -0
  2. requirements.txt +75 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import easyocr
2
+ import json
3
+ import gradio as gr
4
+
5
+ # Initialize reader for your language (assuming English and French are relevant)
6
+ reader = easyocr.Reader(['en', 'fr'])
7
+
8
+
9
+ def extract_inbody_data(image):
10
+ # Extract text from the image
11
+ result = reader.readtext(image, detail = 0)
12
+
13
+ # Process the extracted text into structured format
14
+ try:
15
+ #print(result)
16
+ processed_output = extract_and_convert(result)
17
+ # Convert to JSON
18
+ json_output = json.dumps(processed_output, indent = 2)
19
+ return json_output
20
+ except (IndexError, ValueError) as e:
21
+ return f"Error processing image: {str(e)}"
22
+
23
+
24
+ # Function to extract numbers and convert to float
25
+ def extract_and_convert(data):
26
+ # Extract elements that represent valid numbers (using isdigit or casting as float)
27
+ numbers = []
28
+ for item in data:
29
+ try:
30
+ # Convert to float if possible
31
+ num = float(item)
32
+ numbers.append(num)
33
+ except ValueError:
34
+ continue # Ignore non-numeric values
35
+
36
+ # Ensure we have exactly 6 values (height, age, weight, MMS, body fats, and ratio)
37
+ if len(numbers) >= 6:
38
+ height = numbers[0]
39
+ age = numbers[1]
40
+ weight = correct_float(numbers[2])
41
+ mms = correct_float(numbers[3])
42
+ body_fats = correct_float(numbers[4])
43
+ ratio = numbers[5]
44
+
45
+ return {
46
+ "Height": height,
47
+ "Age": age,
48
+ "Weight": weight,
49
+ "MMS": mms,
50
+ "Body Fats": body_fats,
51
+ "Ratio": ratio
52
+ }
53
+ else:
54
+ return {}
55
+
56
+ def correct_float(num):
57
+ if num > 100:
58
+ return round(num/10,2)
59
+ else:
60
+ return num
61
+
62
+ # Create Gradio Interface
63
+ interface = gr.Interface(
64
+ fn = extract_inbody_data,
65
+ inputs = gr.Image(type = "filepath", label = "Upload InBody Image"),
66
+ outputs = "json",
67
+ title = "InBody Data Extractor",
68
+ description = "Upload an InBody machine screen image and extract health data (Taille, Age, Poids, MMS, TGC).",
69
+ )
70
+
71
+ if __name__ == '__main__':
72
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ annotated-types==0.7.0
3
+ anyio==4.6.0
4
+ certifi==2024.8.30
5
+ charset-normalizer==3.3.2
6
+ click==8.1.7
7
+ contourpy==1.3.0
8
+ cycler==0.12.1
9
+ easyocr==1.7.2
10
+ exceptiongroup==1.2.2
11
+ fastapi==0.115.0
12
+ ffmpy==0.4.0
13
+ filelock==3.16.1
14
+ fonttools==4.54.1
15
+ fsspec==2024.9.0
16
+ gradio==4.44.0
17
+ gradio_client==1.3.0
18
+ h11==0.14.0
19
+ httpcore==1.0.5
20
+ httpx==0.27.2
21
+ huggingface-hub==0.25.1
22
+ idna==3.10
23
+ imageio==2.35.1
24
+ importlib_resources==6.4.5
25
+ Jinja2==3.1.4
26
+ kiwisolver==1.4.7
27
+ lazy_loader==0.4
28
+ markdown-it-py==3.0.0
29
+ MarkupSafe==2.1.5
30
+ matplotlib==3.9.2
31
+ mdurl==0.1.2
32
+ mpmath==1.3.0
33
+ networkx==3.2.1
34
+ ninja==1.11.1.1
35
+ numpy==2.0.2
36
+ opencv-python-headless==4.10.0.84
37
+ orjson==3.10.7
38
+ packaging==24.1
39
+ pandas==2.2.3
40
+ pillow==10.4.0
41
+ pyclipper==1.3.0.post5
42
+ pydantic==2.9.2
43
+ pydantic_core==2.23.4
44
+ pydub==0.25.1
45
+ Pygments==2.18.0
46
+ pyparsing==3.1.4
47
+ python-bidi==0.6.0
48
+ python-dateutil==2.9.0.post0
49
+ python-multipart==0.0.10
50
+ pytz==2024.2
51
+ PyYAML==6.0.2
52
+ requests==2.32.3
53
+ rich==13.8.1
54
+ ruff==0.6.8
55
+ scikit-image==0.24.0
56
+ scipy==1.13.1
57
+ semantic-version==2.10.0
58
+ shapely==2.0.6
59
+ shellingham==1.5.4
60
+ six==1.16.0
61
+ sniffio==1.3.1
62
+ starlette==0.38.6
63
+ sympy==1.13.3
64
+ tifffile==2024.8.30
65
+ tomlkit==0.12.0
66
+ torch==2.4.1
67
+ torchvision==0.19.1
68
+ tqdm==4.66.5
69
+ typer==0.12.5
70
+ typing_extensions==4.12.2
71
+ tzdata==2024.2
72
+ urllib3==2.2.3
73
+ uvicorn==0.30.6
74
+ websockets==12.0
75
+ zipp==3.20.2