DHEIVER commited on
Commit
758c978
·
1 Parent(s): 406e1b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -1,30 +1,26 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Carregue a pipeline de classificação de imagem ViT
5
- image_classifier = pipeline("image-classification", model="mrm8488/vit-base-patch16-224_finetuned-kvasirv2-colonoscopy")
 
 
 
 
6
 
7
- # Função para classificar a imagem
8
  def classify_image(img):
9
- # Execute a classificação da imagem usando a pipeline
10
- result = image_classifier(img)
11
- label = result[0]['label']
12
- probability = result[0]['score']
13
-
14
- # Formate o resultado para exibição
15
- output_text = f"Classe: {label}, Probabilidade: {probability:.2f}"
16
-
17
- return output_text
18
 
19
- # Interface Gradio
20
  iface = gr.Interface(
21
  fn=classify_image,
22
- inputs=gr.inputs.Image(),
23
- outputs=gr.outputs.Textbox(),
24
- live=True,
25
- title="ViT Image Classifier",
26
- description="Carregue uma imagem para classificação.",
27
  )
28
 
29
- if __name__ == "__main__":
30
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import ViTFeatureExtractor, ViTForImageClassification
3
+ from hugsvision.inference.VisionClassifierInference import VisionClassifierInference
4
 
5
+ # Load the pre-trained ViT model
6
+ path = "mrm8488/vit-base-patch16-224_finetuned-kvasirv2-colonoscopy"
7
+ classifier = VisionClassifierInference(
8
+ feature_extractor=ViTFeatureExtractor.from_pretrained(path),
9
+ model=ViTForImageClassification.from_pretrained(path),
10
+ )
11
 
12
+ # Define a Gradio interface
13
  def classify_image(img):
14
+ label = classifier.predict(img_path=img)
15
+ return f"Predicted class: {label}"
 
 
 
 
 
 
 
16
 
 
17
  iface = gr.Interface(
18
  fn=classify_image,
19
+ inputs=gr.inputs.Image(type="file", label="Upload an image"),
20
+ outputs="text",
21
+ title="Image Classifier",
22
+ description="Classify images using a pre-trained ViT model",
 
23
  )
24
 
25
+ # Launch the Gradio app
26
+ iface.launch()