Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
from tensorflow.keras.models import load_model
|
5 |
-
import string
|
6 |
|
7 |
-
# Load
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
class_names = list(string.ascii_lowercase[:26].replace('j', '').replace('z', ''))
|
12 |
-
|
13 |
-
# Function to predict the sign language from the image
|
14 |
def predict(image):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# Predict using the trained model
|
21 |
-
predictions = model.predict(image)
|
22 |
-
predicted_class = np.argmax(predictions, axis=1)[0]
|
23 |
-
|
24 |
-
# Return the predicted class
|
25 |
-
return class_names[predicted_class]
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
outputs="text",
|
32 |
-
live=True,
|
33 |
-
title="Sign Language Recognition",
|
34 |
-
description="Upload a sign language image, and the model will predict the corresponding letter."
|
35 |
-
)
|
36 |
|
37 |
-
|
38 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
|
|
|
|
4 |
|
5 |
+
# Load model and feature extractor (adjust these according to your model)
|
6 |
+
model_name = "sign_language_model(1).h5" # Replace with your model path or Hugging Face model
|
7 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
8 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
9 |
|
10 |
+
# Define prediction function
|
|
|
|
|
|
|
11 |
def predict(image):
|
12 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
13 |
+
with torch.no_grad():
|
14 |
+
logits = model(**inputs).logits
|
15 |
+
predicted_class = logits.argmax(-1).item()
|
16 |
+
return predicted_class
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Set up the Gradio interface
|
19 |
+
interface = gr.Interface(fn=predict,
|
20 |
+
inputs=gr.Image(type="pil"),
|
21 |
+
outputs=gr.Text(label="Predicted Sign Language"))
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
if __name__ == "__main__":
|
24 |
+
interface.launch()
|