Marxulia commited on
Commit
a925304
·
verified ·
1 Parent(s): 8923a71

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+ from PIL import UnidentifiedImageError
5
+
6
+ def sign_classifier(input_image):
7
+ try:
8
+ # Load the image
9
+ image = input_image
10
+
11
+ # Emotion classifier
12
+ sign_pipe = pipeline("image-classification", model="Marxulia/asl_aplhabet_img_classifier_v3")
13
+ sign_result = sign_pipe(image)
14
+ predicted_sign = sign_result[0]['label']
15
+ sign_confidence = sign_result[0]['score']
16
+
17
+ # Format the results
18
+ sign_output = f"Sign Prediction: {predicted_sign}\nConfidence: {sign_confidence}"
19
+
20
+ return sign_output
21
+
22
+ except UnidentifiedImageError:
23
+ return "Error: Invalid input image format."
24
+
25
+ # Load an example image (replace 'path/to/your/image.jpg' with your actual path)
26
+ example_image1 = Image.open('H3.jpg')
27
+ example_image2 = Image.open('B3.jpg')
28
+
29
+ # Create Gradio interface
30
+ input_image = gr.Image(type="pil", label="Upload Image")
31
+ output_sign = gr.Textbox(label="Sign Classifier")
32
+
33
+ # Provide a list of examples, where each element is a list with the input and output
34
+ examples = [[example_image1, "H Sign"],[example_image2, "B Sign"]] # Modify the output based on your image
35
+
36
+ # Include examples in the interface
37
+ interface = gr.Interface(fn=sign_classifier, inputs=input_image, outputs=[output_sign],
38
+ title="Image Classifier", description="Upload an image and translate the sign", examples=examples)
39
+
40
+ interface.launch(debug=True)