Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the model pipeline
|
5 |
+
pipe = pipeline("image-classification", "dima806/medicinal_plants_image_detection")
|
6 |
+
|
7 |
+
# Define the image classification function
|
8 |
+
def image_classifier(image):
|
9 |
+
# Perform image classification
|
10 |
+
outputs = pipe(image)
|
11 |
+
# Get the label of the first result
|
12 |
+
output_text = outputs[0]['label']
|
13 |
+
return output_text
|
14 |
+
|
15 |
+
# Define app title and description with HTML formatting
|
16 |
+
title = "<h1 style='text-align: center; color: #4CAF50;'>Indian Medicinal Plant Identification</h1>"
|
17 |
+
description = "<p style='text-align: center; font-size: 18px;'></p>"
|
18 |
+
|
19 |
+
# Define custom CSS styles for the Gradio app
|
20 |
+
custom_css = """
|
21 |
+
.gradio-interface {
|
22 |
+
max-width: 600px;
|
23 |
+
margin: auto;
|
24 |
+
border-radius: 10px;
|
25 |
+
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
|
26 |
+
}
|
27 |
+
.title-container {
|
28 |
+
padding: 20px;
|
29 |
+
background-color: #f0f0f0;
|
30 |
+
border-top-left-radius: 10px;
|
31 |
+
border-top-right-radius: 10px;
|
32 |
+
}
|
33 |
+
.description-container {
|
34 |
+
padding: 20px;
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
# Launch the Gradio interface with custom HTML and CSS
|
39 |
+
demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="textbox", title=title, description=description,
|
40 |
+
theme="gstaff/sketch", css=custom_css,
|
41 |
+
)
|
42 |
+
demo.launch()
|