Og2 commited on
Commit
250423a
·
verified ·
1 Parent(s): 29d0ad4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -61
app.py CHANGED
@@ -1,54 +1,22 @@
1
- #curl -H "Accept: application/json" https://Og2-wstest.hf.space/
2
- #curl -H "Accept: application/json" https://Og2-wstest.hf.space/hello/
3
- #curl -X POST https://Og2-wstest.hf.space/muws2/ -H "Content-Type: application/json" -d "{\"text\": \"Ceci est un texte exemple.\"}"
4
- #curl -X POST "https://Og2-wstest.hf.space/upload-video/" -H "Content-Type: multipart/form-data" -F "file=@E:\nosave\MyDocs\AndroidStudio\PythonProjects\SportHobbyStats\Foosball\VideoAnnotation\MoviNet2\train\Block_1-2.1/CNFT2Toulouse_Block_1729.avi"
5
-
6
 
7
  from fastapi import FastAPI, File, Form, UploadFile, HTTPException
8
  from pathlib import Path
9
  import os
10
  from pydantic import BaseModel
11
  import json
 
 
 
 
 
 
 
 
 
12
 
13
  app = FastAPI()
14
 
15
- # Définir un modèle pour recevoir un texte
16
- class TextInput(BaseModel):
17
- text: str
18
-
19
- @app.post("/muws2/")
20
- def process_text(input_data: TextInput):
21
- # Récupérer le texte depuis l'entrée
22
- input_text = input_data.text
23
-
24
- # Créer un dictionnaire JSON avec le texte en sortie
25
- output = {
26
- "text": input_text
27
- }
28
-
29
- return output
30
-
31
- @app.get("/hello/")
32
- def greet_hello():
33
- return {"msg": "Hello World!"}
34
-
35
- @app.get("/")
36
- def greet_hello():
37
- return {"msg": "Ok!"}
38
-
39
-
40
- @app.post("/upload-video/")
41
- async def upload_video(file: UploadFile = File(...)):
42
- # Lire le contenu du fichier
43
- content = await file.read()
44
- # Vous pouvez sauvegarder la vidéo ou la traiter ici
45
- with open(f"uploaded_{file.filename}", "wb") as f:
46
- f.write(content)
47
-
48
- return {"filename": file.filename, "content_type": file.content_type}
49
-
50
-
51
-
52
  UPLOAD_DIR = "uploads"
53
  os.makedirs(UPLOAD_DIR, exist_ok=True)
54
 
@@ -96,20 +64,11 @@ async def upload_file(
96
 
97
 
98
 
99
- import tensorflow as tf
100
- import numpy as np
101
- import cv2
102
- import keras
103
- from keras.saving import register_keras_serializable
104
- from keras import layers
105
- from huggingface_hub import hf_hub_download
106
- from keras.applications.densenet import DenseNet121
107
- #from tensorflow_docs.vis import embed
108
 
109
  # Available backend options are: "jax", "torch", "tensorflow".
110
  os.environ["KERAS_BACKEND"] = "tensorflow"
111
 
112
-
113
  # Charger le modèle Keras
114
  MAX_SEQ_LENGTH = 8
115
  NUM_FEATURES = 1024
@@ -119,8 +78,6 @@ IMG_SIZE = 128
119
  # Au lieu de CenterCrop
120
  center_crop_layer = layers.Resizing(IMG_SIZE, IMG_SIZE)
121
 
122
-
123
-
124
  def crop_center(frame):
125
  cropped = center_crop_layer(frame[None, ...])
126
  cropped = keras.ops.convert_to_numpy(cropped)
@@ -224,16 +181,10 @@ model = keras.saving.load_model("hf://Og2/videoclassif", custom_objects={'Positi
224
  # Identifier le modèle Hugging Face et le fichier que vous voulez lire
225
  model_repo = "Og2/videoclassif" # Remplacez par votre modèle spécifique
226
  file_name = "labels.txt" # Le fichier que vous voulez télécharger
227
-
228
  # Télécharger le fichier depuis Hugging Face Hub
229
  labels_file_path = hf_hub_download(repo_id=model_repo, filename=file_name)
230
-
231
- # Liste des classes du modèle
232
- # Nom du fichier de classe
233
- #input_file = "hf://Og2/videoclassif/labels.txt"
234
- # Lecture du fichier et création de la liste
235
  with open(labels_file_path, "r") as file:
236
- class_labels = [line.strip() for line in file]
237
  #print("Tableau recréé à partir du fichier :")
238
  #print(class_labels)
239
 
 
1
+ # https://Og2-wstest.hf.space/
 
 
 
 
2
 
3
  from fastapi import FastAPI, File, Form, UploadFile, HTTPException
4
  from pathlib import Path
5
  import os
6
  from pydantic import BaseModel
7
  import json
8
+ import tensorflow as tf
9
+ import numpy as np
10
+ import cv2
11
+ import keras
12
+ from keras.saving import register_keras_serializable
13
+ from keras import layers
14
+ from huggingface_hub import hf_hub_download
15
+ from keras.applications.densenet import DenseNet121
16
+ #from tensorflow_docs.vis import embed
17
 
18
  app = FastAPI()
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  UPLOAD_DIR = "uploads"
21
  os.makedirs(UPLOAD_DIR, exist_ok=True)
22
 
 
64
 
65
 
66
 
67
+
 
 
 
 
 
 
 
 
68
 
69
  # Available backend options are: "jax", "torch", "tensorflow".
70
  os.environ["KERAS_BACKEND"] = "tensorflow"
71
 
 
72
  # Charger le modèle Keras
73
  MAX_SEQ_LENGTH = 8
74
  NUM_FEATURES = 1024
 
78
  # Au lieu de CenterCrop
79
  center_crop_layer = layers.Resizing(IMG_SIZE, IMG_SIZE)
80
 
 
 
81
  def crop_center(frame):
82
  cropped = center_crop_layer(frame[None, ...])
83
  cropped = keras.ops.convert_to_numpy(cropped)
 
181
  # Identifier le modèle Hugging Face et le fichier que vous voulez lire
182
  model_repo = "Og2/videoclassif" # Remplacez par votre modèle spécifique
183
  file_name = "labels.txt" # Le fichier que vous voulez télécharger
 
184
  # Télécharger le fichier depuis Hugging Face Hub
185
  labels_file_path = hf_hub_download(repo_id=model_repo, filename=file_name)
 
 
 
 
 
186
  with open(labels_file_path, "r") as file:
187
+ class_labels = [line.strip() for line in file] # Lecture du fichier et création de la liste
188
  #print("Tableau recréé à partir du fichier :")
189
  #print(class_labels)
190