Deva commited on
Commit ·
91bda11
1
Parent(s): 3db78b4
Feature Get the Output.csv
Browse files- .gitignore +2 -1
- app.py +65 -15
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
test_images/*
|
|
|
|
|
|
| 1 |
+
test_images/*
|
| 2 |
+
*.csv
|
app.py
CHANGED
|
@@ -6,29 +6,79 @@ from tkinter import Tk, filedialog
|
|
| 6 |
import gradio as gr
|
| 7 |
from pathlib import Path
|
| 8 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
|
|
|
| 9 |
import torch
|
| 10 |
|
|
|
|
| 11 |
# Load model
|
| 12 |
-
processor = AutoImageProcessor.from_pretrained("victor/animals-classifier")
|
| 13 |
-
model = AutoModelForImageClassification.from_pretrained("victor/animals-classifier")
|
| 14 |
-
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
df = pd.DataFrame(columns=["file_name", "label", "accuracy"])
|
| 20 |
-
df["file_name"] =
|
| 21 |
-
df["label"] = "incoming"
|
| 22 |
-
df["accuracy"] = 100
|
| 23 |
return df
|
| 24 |
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# file_output = gr.File()
|
| 31 |
-
output_df = gr.DataFrame()
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
from pathlib import Path
|
| 8 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 9 |
+
from io import BytesIO
|
| 10 |
import torch
|
| 11 |
|
| 12 |
+
|
| 13 |
# Load model
|
| 14 |
+
# processor = AutoImageProcessor.from_pretrained("victor/animals-classifier")
|
| 15 |
+
# model = AutoModelForImageClassification.from_pretrained("victor/animals-classifier")
|
| 16 |
+
# model.eval()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_file_names(files_):
|
| 20 |
+
"""
|
| 21 |
+
Get a list of the name of files splitted to get only the proper name
|
| 22 |
+
Input: Uploaded files
|
| 23 |
+
Output: ['name of file 1', 'name of file 2']"""
|
| 24 |
+
return [file.name.split("/")[-1] for file in files_]
|
| 25 |
|
| 26 |
|
| 27 |
+
def get_annotation(files_):
|
| 28 |
+
"""
|
| 29 |
+
Get the label and accuracy from pretrained (or futur custom model)
|
| 30 |
+
Input: Uploaded files
|
| 31 |
+
Output: Df that contains: file_name | label | accuracy
|
| 32 |
+
"""
|
| 33 |
df = pd.DataFrame(columns=["file_name", "label", "accuracy"])
|
| 34 |
+
df["file_name"] = get_file_names(files_)
|
| 35 |
+
df["label"] = "incoming" # TODO
|
| 36 |
+
df["accuracy"] = 100 # TODO
|
| 37 |
return df
|
| 38 |
|
| 39 |
|
| 40 |
+
def df_to_csv(df_):
|
| 41 |
+
"""
|
| 42 |
+
Get the df and convert it as an gradio file output ready for download
|
| 43 |
+
Input: DF created
|
| 44 |
+
Output: gr.File()
|
| 45 |
+
"""
|
| 46 |
+
df_.to_csv("output.csv", index=False)
|
| 47 |
+
return gr.File(value="output.csv", visible=True)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def process_files(files_):
|
| 51 |
+
"""
|
| 52 |
+
Main function
|
| 53 |
+
- Get uploaded files
|
| 54 |
+
- Get annotations # TODO
|
| 55 |
+
- Get the corresponding df
|
| 56 |
+
- Get the csv output
|
| 57 |
+
"""
|
| 58 |
+
df = get_annotation(files_)
|
| 59 |
+
output_csv = df_to_csv(df)
|
| 60 |
+
print(df)
|
| 61 |
+
print(output_csv)
|
| 62 |
+
print("test")
|
| 63 |
+
return [df, output_csv]
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
title = "Demo: zero-shot depth estimation with DPT + 3D Point Cloud"
|
| 67 |
+
description = "This demo is a variation from the original <a href='https://huggingface.co/spaces/nielsr/dpt-depth-estimation' target='_blank'>DPT Demo</a>. It uses the DPT model to predict the depth of an image and then uses 3D Point Cloud to create a 3D object."
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
with gr.Blocks() as interface:
|
| 71 |
+
with gr.Row():
|
| 72 |
+
upload_btn = gr.UploadButton(
|
| 73 |
+
"Click to Upload a File",
|
| 74 |
+
file_types=["image", "video"],
|
| 75 |
+
file_count="multiple",
|
| 76 |
+
)
|
| 77 |
# file_output = gr.File()
|
| 78 |
+
# output_df = gr.DataFrame()
|
| 79 |
+
upload_btn.upload(
|
| 80 |
+
fn=process_files, inputs=upload_btn, outputs=[gr.DataFrame(), gr.Files()]
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
|
| 84 |
+
interface.launch(debug=True)
|