IDS75912 commited on
Commit
27384f5
·
1 Parent(s): 89af506
Files changed (1) hide show
  1. main.py +9 -42
main.py CHANGED
@@ -12,41 +12,19 @@ from PIL import Image
12
  from typing import Any, Dict
13
  import os
14
  import pkgutil
15
- print('starlette', __import__('starlette').__version__)
16
 
17
  from huggingface_hub import hf_hub_download
18
  from typing import Any, Dict
19
 
20
  import tensorflow as tf
21
- print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
22
- if tf.config.list_physical_devices('GPU'):
23
- print(tf.config.list_physical_devices('GPU')[0].device_type, tf.config.list_physical_devices('GPU')[0].name )
24
 
25
  from tensorflow import keras
26
- TF_AVAILABLE = True
27
- print("tensorflow version: ", tf.__version__)
28
- print("keras version: ", keras.__version__)
29
-
30
-
31
- # starlette is a FastAPI dependency; import if available
32
- try:
33
- import starlette
34
- except Exception:
35
- starlette = None
36
-
37
- # TensorFlow can be large or absent in some envs; guard the import so
38
- # importing this module doesn't crash tests or other tooling.
39
- try:
40
- import tensorflow as tf
41
- from tensorflow import keras
42
- TF_AVAILABLE = True
43
- print("tensorflow version: ", tf.__version__)
44
- print("keras version: ", keras.__version__)
45
- except Exception:
46
- tf = None
47
- keras = None
48
- TF_AVAILABLE = False
49
- print("tensorflow not available")
50
 
51
 
52
  app = FastAPI(title="1.3 - AI Model Deployment")
@@ -112,26 +90,15 @@ def versions() -> Dict[str, Any]:
112
  """Return key package versions and whether TensorFlow is available."""
113
  return {
114
  "fastapi": fastapi.__version__,
115
- "starlette": getattr(starlette, "__version__", None),
116
- "tensorflow_available": TF_AVAILABLE,
117
- "tensorflow_version": getattr(tf, "__version__", None),
118
  }
119
 
120
 
121
  @app.get("/predict")
122
  def predict_stub() -> Dict[str, Any]:
123
- """A tiny predict stub that demonstrates how to expose model inference.
124
-
125
- If TensorFlow isn't available or no model is loaded this returns a helpful
126
- message.
127
- """
128
- if not TF_AVAILABLE or model is None:
129
- return {
130
- "prediction": "N/A",
131
- "info": "TensorFlow not available or model not loaded.",
132
- }
133
  # This is a stub, so we're not doing a real prediction
134
- return {"prediction": "stub, we're not doing a real prediction", "model_path": model_path}
135
 
136
 
137
 
 
12
  from typing import Any, Dict
13
  import os
14
  import pkgutil
15
+
16
 
17
  from huggingface_hub import hf_hub_download
18
  from typing import Any, Dict
19
 
20
  import tensorflow as tf
21
+
22
+
 
23
 
24
  from tensorflow import keras
25
+
26
+
27
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
 
30
  app = FastAPI(title="1.3 - AI Model Deployment")
 
90
  """Return key package versions and whether TensorFlow is available."""
91
  return {
92
  "fastapi": fastapi.__version__,
93
+
 
 
94
  }
95
 
96
 
97
  @app.get("/predict")
98
  def predict_stub() -> Dict[str, Any]:
99
+
 
 
 
 
 
 
 
 
 
100
  # This is a stub, so we're not doing a real prediction
101
+ return {"prediction": "stub, we're not doing a real prediction"}
102
 
103
 
104