dlaima commited on
Commit
13bcf5a
·
verified ·
1 Parent(s): d564297

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install and update the necessary libraries
2
+ import logging
3
+ import sys
4
+ from PIL import Image
5
+ from transformers import pipeline
6
+ import os
7
+ import gradio as gr
8
+
9
+ # Suppress non-critical log messages
10
+ from transformers.utils import logging
11
+ logging.set_verbosity_error()
12
+
13
+ #from helper import ignore_warnings
14
+ #ignore_warnings()
15
+ #import sys
16
+ #sys.path.append("./Open_Source_Models_with_Hugging_Face/Object_Detection/helper.py") # Adjust the path as necessary to point to the directory where helper.py is located
17
+
18
+ from Open_Source_Models_with_Hugging_Face.Object_Detection.helper import ignore_warnings
19
+ ignore_warnings()
20
+
21
+ # Import the pipeline function from the transformers library
22
+ #from transformers import pipeline
23
+
24
+ # Set up the object detection pipeline.
25
+ pipe = pipeline("object-detection", model="facebook/detr-resnet-50")
26
+
27
+ #sys.path.append("./Open_Source_Models_with_Hugging_Face/Object_Detection/helper.py") # Adjust the path as necessary to point to the directory where helper.py is located
28
+
29
+ #from Open_Source_Models_with_Hugging_Face.Object_Detection.helper import load_image_from_url, render_results_in_image
30
+
31
+ # Load the image from a file
32
+ #raw_image = Image.open('./Open_Source_Models_with_Hugging_Face/Object_Detection/kittens.jpeg')
33
+ # Resize the image
34
+ #raw_image.resize((569, 491))
35
+
36
+ #pipeline_output = pipe(raw_image)
37
+ #processed_image = render_results_in_image(raw_image, pipeline_output)
38
+ #processed_image
39
+
40
+ # gradio interface
41
+ def get_pipeline_prediction(pil_image):
42
+ pipeline_output = pipe(pil_image)
43
+ processed_image = render_results_in_image(pil_image, pipeline_output)
44
+ return processed_image
45
+
46
+ demo = gr.Interface(
47
+ fn=get_pipeline_prediction,
48
+ inputs=gr.Image(label="Input image",
49
+ type="pil"),
50
+ outputs=gr.Image(label="Output image with predicted instances",
51
+ type="pil")
52
+ )
53
+
54
+
55
+ demo.launch(share=True)
56
+
57
+