vincentclaes commited on
Commit
fd2ef9c
1 Parent(s): 0962672

working model

Browse files
README.md CHANGED
@@ -1,12 +1,22 @@
1
  ---
2
  title: Mona Lisa Detection
3
- emoji: 💻
4
- colorFrom: indigo
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 3.19.1
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Mona Lisa Detection
3
+ emoji: 🖼
4
+ colorFrom: white
5
+ colorTo: white
6
  sdk: gradio
7
  sdk_version: 3.19.1
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ ## Setup + Run
16
+ ```bash
17
+ virtualenv .venv
18
+ source .venv/bin/activate
19
+ pip install -r requirements.txt
20
+ python app.py
21
+
22
+ ```
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib
2
+ import gradio as gr
3
+ from loguru import logger
4
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
5
+
6
+ logger.info("starting gradio app")
7
+
8
+ CURRENT_DIR = pathlib.Path(__file__).resolve().parent
9
+ APP_NAME = "Mona Lisa Detection"
10
+
11
+ logger.debug("loading processor and model.")
12
+ processor = AutoFeatureExtractor.from_pretrained(
13
+ "drift-ai/autotrain-mona-lisa-detection-38345101350"
14
+ )
15
+ model = AutoModelForImageClassification.from_pretrained(
16
+ "drift-ai/autotrain-mona-lisa-detection-38345101350"
17
+ )
18
+ logger.debug("loading processor and model succeeded.")
19
+
20
+
21
+ def process_image(image, model=model, processor=processor):
22
+ logger.info("Making a prediction ...")
23
+ inputs = processor(images=image, return_tensors="pt")
24
+ outputs = model(**inputs)
25
+ logits = outputs.logits
26
+ predicted_class_idx = logits.argmax(-1).item()
27
+ result = model.config.id2label[predicted_class_idx]
28
+ print("Predicted class:", result)
29
+ logger.info("Prediction finished.")
30
+ return result
31
+
32
+
33
+ examples = [
34
+ "mona-lisa-1.jpg",
35
+ "mona-lisa-2.jpg",
36
+ "mona-lisa-3.jpg",
37
+ "not-mona-lisa-1.jpg",
38
+ "not-mona-lisa-2.jpg",
39
+ "not-mona-lisa-3.jpg",
40
+ ]
41
+
42
+ if __name__ == "__main__":
43
+ title = """
44
+ Mona Lisa Detection.
45
+ """
46
+ app = gr.Interface(
47
+ fn=process_image,
48
+ inputs=[
49
+ gr.inputs.Image(type="pil", label="Image"),
50
+ ],
51
+ outputs=gr.Label(label="Predictions:", show_label=True),
52
+ examples=examples,
53
+ examples_per_page=32,
54
+ title=title,
55
+ enable_queue=True,
56
+ ).launch()
mona-lisa-1.jpg ADDED
mona-lisa-2.jpg ADDED
mona-lisa-3.jpg ADDED
not-mona-lisa-1.jpg ADDED
not-mona-lisa-2.jpg ADDED
not-mona-lisa-3.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ loguru
2
+ gradio
3
+ transformers
4
+ torch