JefferyJapheth commited on
Commit
808add1
1 Parent(s): e006e03

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -36
app.py CHANGED
@@ -1,46 +1,27 @@
1
  import gradio as gr
2
-
3
-
4
-
5
-
6
  import numpy as np
7
- from transformers import TFLiteModel
8
-
9
- # Load the TFLite model from Hugging Face
10
- model = TFLiteModel.from_pretrained('https://huggingface.co/spaces/JefferyJapheth/sega/blob/main/model.tflite')
11
-
12
- # Define preprocessing function for .npy files
13
- def preprocess_frame(file_path):
14
- # Load the .npy file
15
- frame_data = np.load(file_path)
16
 
17
- # Replace this with any preprocessing needed for your model
18
- # For example, normalization, reshaping, etc.
19
- processed_frame = frame_data # Replace this with your actual preprocessing code
20
- return processed_frame
21
 
22
- # Provide the fixed file path for the .npy input
23
- npy_file_path = "https://huggingface.co/spaces/JefferyJapheth/sega/blob/main/NON_EMPTY_FRAME_IDXS.npy"
24
-
25
- # Define the predict_sign_language function for Gradio interface
26
- def predict_sign_language(webcam_frame):
27
- # Preprocess the .npy file
28
- processed_frame = preprocess_frame(npy_file_path)
29
-
30
- # Process the webcam frame (convert Gradio's image format to numpy array if needed)
31
- webcam_frame_np = webcam_frame
32
-
33
- # Combine the frames, or perform any required processing
34
-
35
- # Run inference using the TFLite model
36
- prediction = model(processed_frame)
37
 
38
  # ... (post-processing if required)
39
 
40
  return prediction
41
 
42
- # Create the Gradio interface with a webcam input
43
- webcam_input = gr.inputs.Image(shape=(224, 224)) # Set the shape according to your model's requirements
 
 
 
 
 
 
44
 
45
- iface = gr.Interface(fn=predict_sign_language, inputs=webcam_input, outputs="text")
46
- iface.launch(share=True) # Set `share=True` to make it accessible outside the localhost
 
1
  import gradio as gr
2
+ import tensorflow as tf
 
 
 
3
  import numpy as np
 
 
 
 
 
 
 
 
 
4
 
5
+ # Load your sign language prediction model
6
+ model = tf.keras.models.load_model(r"C:\Users\Jeffery.st\Desktop\st.Jeffery00\mega\model.h5")
 
 
7
 
8
+ # Define the prediction function
9
+ def predict_sign_language(image):
10
+ # Run inference using the model
11
+ prediction = model.predict(np.expand_dims(image, axis=0))
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # ... (post-processing if required)
14
 
15
  return prediction
16
 
17
+ # Define the webcam input component
18
+ webcam_input = gr.inputs.Image(source="webcam")
19
+
20
+ # Define the output component
21
+ label_output = gr.outputs.Label()
22
+
23
+ # Create the Gradio interface
24
+ iface = gr.Interface(fn=predict_sign_language, inputs=webcam_input, outputs=label_output)
25
 
26
+ # Launch the interface
27
+ iface.launch()