File size: 1,446 Bytes
a925304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f308c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
from transformers import pipeline
from PIL import Image
from PIL import UnidentifiedImageError

def sign_classifier(input_image):
  try:
    # Load the image
    image = input_image

    # Emotion classifier
    sign_pipe = pipeline("image-classification", model="Marxulia/asl_aplhabet_img_classifier_v3")
    sign_result = sign_pipe(image)
    predicted_sign = sign_result[0]['label']
    sign_confidence = sign_result[0]['score']

    # Format the results
    sign_output = f"Sign Prediction: {predicted_sign}\nConfidence: {sign_confidence}"

    return sign_output

  except UnidentifiedImageError:
    return "Error: Invalid input image format."

# Load an example image (replace 'path/to/your/image.jpg' with your actual path)
example_image1 = Image.open('H3.jpg')
example_image2 = Image.open('B3.jpg')

# Create Gradio interface
input_image = gr.Image(type="pil", label="Upload Image")
output_sign = gr.Textbox(label="Sign Classifier")

# Provide a list of examples, where each element is a list with the input and output
examples = [[example_image1, "H Sign"],[example_image2, "B Sign"]]  # Modify the output based on your image

# Include examples in the interface
interface = gr.Interface(fn=sign_classifier, inputs=input_image, outputs=[output_sign], 
                         title="Image Classifier", description="Upload an image and translate the sign", examples=examples)

interface.launch(share=True,debug=True)