Spaces:
Running
Running
Build initial app.py code
Browse files
app.py
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import TFAutoModel
|
| 3 |
+
|
| 4 |
+
PATH = "./4-15_ViT-B16_Lung3_v1"
|
| 5 |
+
model = TFAutoModel.from_pretrained(PATH)
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(PATH)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Define preprocessing function
|
| 10 |
+
# def preprocess_image(image):
|
| 11 |
+
# # Add preprocessing steps here (e.g., resizing, normalization)
|
| 12 |
+
# # Return preprocessed image
|
| 13 |
+
# return image
|
| 14 |
+
|
| 15 |
+
# Define inference function
|
| 16 |
+
def predict(preprocessed_image):
|
| 17 |
+
# Preprocess the image
|
| 18 |
+
# preprocessed_image = preprocess_image(image)
|
| 19 |
+
|
| 20 |
+
# Convert preprocessed image to input format expected by the model
|
| 21 |
+
inputs = tokenizer(preprocessed_image, return_tensors="tf")
|
| 22 |
+
|
| 23 |
+
# Perform model inference
|
| 24 |
+
outputs = model(**inputs)
|
| 25 |
+
|
| 26 |
+
# Process model outputs as needed
|
| 27 |
+
# For example, extract predicted labels
|
| 28 |
+
predicted_labels = np.argmax(outputs.logits.numpy(), axis=1)
|
| 29 |
+
|
| 30 |
+
# Return predicted labels
|
| 31 |
+
return predicted_labels
|
| 32 |
+
|
| 33 |
+
image_component = gr.Image(type="numpy", label="Chest X-ray Image")
|
| 34 |
+
label_component = gr.Label(label="Classification result", num_top_classes=1)
|
| 35 |
+
description = ""
|
| 36 |
+
title = "Pneumonia Classifier 🐣"
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(fn=predict, inputs=image_component, outputs=label_component, description=description, title=title)
|
| 39 |
+
|
| 40 |
+
demo.launch()
|