Spaces:
Sleeping
Sleeping
feat: impl basic app
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
key = os.getenv("KEY")
|
| 10 |
+
|
| 11 |
+
pipe = pipeline("image-classification", model="Nech-C/mineralimage5K-98", device='cpu')
|
| 12 |
+
|
| 13 |
+
def classify_image(image):
|
| 14 |
+
# [{'label': 'quartz', 'score': 0.20238091051578522}, {'label': 'celestine', 'score': 0.11984242498874664},
|
| 15 |
+
# {'label': 'credit', 'score': 0.05711612477898598}, {'label': 'aragonite', 'score': 0.039466191083192825},
|
| 16 |
+
# {'label': 'calcite', 'score': 0.03766309469938278}]
|
| 17 |
+
result = pipe(image)
|
| 18 |
+
output = {}
|
| 19 |
+
for item in result:
|
| 20 |
+
output[item['label']] = item['score']
|
| 21 |
+
return output
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=classify_image,
|
| 24 |
+
inputs=gr.Image(type="pil"),
|
| 25 |
+
outputs=gr.Label(num_top_classes=5),
|
| 26 |
+
title="Rockognize",
|
| 27 |
+
description="A simple app to classify rocks and minerals.",
|
| 28 |
+
theme="default",
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
demo.launch()
|