Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -87,30 +87,114 @@ def classify_image(image):
|
|
87 |
|
88 |
return predicted_class_name, predicted_scores, mineral_key_facts
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
app_title = "Mineral Identification using AI"
|
91 |
app_description = "This application uses advanced machine learning models to accurately identify and classify different types of minerals from images. Simply upload an image, and the system will provide the predicted mineral class along with its key characteristics and properties."
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
with gr.Blocks(
|
94 |
-
title=app_title,
|
95 |
-
css=
|
96 |
theme=gr.themes.Monochrome(),
|
97 |
-
|
|
|
|
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
) as demo:
|
106 |
# Your existing code for creating the interface components
|
107 |
with gr.Row():
|
108 |
image_input = gr.Image(elem_id="image_input", type="pil")
|
109 |
output_components = [
|
110 |
-
gr.Textbox(label="Mineral Name",elem_id="predicted_class_name"),
|
111 |
-
gr.Textbox(label="Prediction Scores of Model",elem_id="predicted_scores", lines=5),
|
112 |
-
gr.Textbox(label="Key Facts About Mineral",elem_id="mineral_key_facts", lines=8)
|
113 |
]
|
114 |
image_button = gr.Button("Classify Mineral")
|
115 |
image_button.click(classify_image, inputs=image_input, outputs=output_components)
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
return predicted_class_name, predicted_scores, mineral_key_facts
|
89 |
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
DESCRIPTION = '''
|
97 |
+
<div>
|
98 |
+
<h1 style="text-align: center;">Microscopic Mineral Identification App</h1>
|
99 |
+
<p>Welcome to our interactive space dedicated to identifying minerals through microscopic imagery. This platform showcases various microscopic images that reveal the intricate patterns and characteristics of different minerals. To get started, you can explore our collection of mineral images or use your own to identify key features such as crystal structure, color variations, and inclusions.</p>
|
100 |
+
<p>🔎 For a deeper understanding of mineral identification techniques and how to analyze microscopic mineral images, visit our comprehensive <a href="https://example.com/mineral-guide">mineral guide</a>. It provides insights into common mineralogical features and how to recognize them.</p>
|
101 |
+
<p>🧪 Interested in more advanced mineralogy? Check out our <a href="https://example.com/advanced-mineralogy"><b>Advanced Mineralogy</b></a> section, where we dive into more complex mineral structures and analytical methods.</p>
|
102 |
+
</div>
|
103 |
+
'''
|
104 |
+
|
105 |
+
|
106 |
+
# Welcome Message
|
107 |
+
def welcome(name):
|
108 |
+
return f"Welcome to Gradio, {name}!"
|
109 |
+
|
110 |
+
js = """
|
111 |
+
function createGradioAnimation() {
|
112 |
+
var container = document.createElement('div');
|
113 |
+
container.id = 'gradio-animation';
|
114 |
+
container.style.fontSize = '2em';
|
115 |
+
container.style.fontWeight = 'bold';
|
116 |
+
container.style.textAlign = 'center';
|
117 |
+
container.style.marginBottom = '20px';
|
118 |
+
|
119 |
+
var text = 'Welcome to Gradio!';
|
120 |
+
for (var i = 0; i < text.length; i++) {
|
121 |
+
(function(i){
|
122 |
+
setTimeout(function(){
|
123 |
+
var letter = document.createElement('span');
|
124 |
+
letter.style.opacity = '0';
|
125 |
+
letter.style.transition = 'opacity 0.5s';
|
126 |
+
letter.innerText = text[i];
|
127 |
+
|
128 |
+
container.appendChild(letter);
|
129 |
+
|
130 |
+
setTimeout(function() {
|
131 |
+
letter.style.opacity = '1';
|
132 |
+
}, 50);
|
133 |
+
}, i * 250);
|
134 |
+
})(i);
|
135 |
+
}
|
136 |
+
|
137 |
+
var gradioContainer = document.querySelector('.gradio-container');
|
138 |
+
gradioContainer.insertBefore(container, gradioContainer.firstChild);
|
139 |
+
|
140 |
+
return 'Animation created';
|
141 |
+
}
|
142 |
+
"""
|
143 |
+
|
144 |
+
|
145 |
app_title = "Mineral Identification using AI"
|
146 |
app_description = "This application uses advanced machine learning models to accurately identify and classify different types of minerals from images. Simply upload an image, and the system will provide the predicted mineral class along with its key characteristics and properties."
|
147 |
|
148 |
+
custom_css = """
|
149 |
+
.gradio-container {display: flex; justify-content: center; align-items: center; height: 100vh;}
|
150 |
+
|
151 |
+
|
152 |
+
#title-container {
|
153 |
+
display: flex;
|
154 |
+
align-items: center;
|
155 |
+
justify-content: center;
|
156 |
+
margin-bottom: 20px;
|
157 |
+
}
|
158 |
+
|
159 |
+
#app-title {
|
160 |
+
margin-right: 20px; /* Adjust the spacing between the title and logo */
|
161 |
+
}
|
162 |
+
|
163 |
+
#logo-img {
|
164 |
+
width: 50px; /* Adjust the logo size as needed */
|
165 |
+
height: 50px;
|
166 |
+
}
|
167 |
+
|
168 |
+
"""
|
169 |
+
|
170 |
+
|
171 |
with gr.Blocks(
|
172 |
+
title=app_title,
|
173 |
+
css=custom_css,
|
174 |
theme=gr.themes.Monochrome(),
|
175 |
+
js=js,
|
176 |
+
) as demo:
|
177 |
+
gr.Markdown(DESCRIPTION)
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
# Your existing code for creating the interface components
|
180 |
with gr.Row():
|
181 |
image_input = gr.Image(elem_id="image_input", type="pil")
|
182 |
output_components = [
|
183 |
+
gr.Textbox(label="Mineral Name", elem_id="predicted_class_name"),
|
184 |
+
gr.Textbox(label="Prediction Scores of Model", elem_id="predicted_scores", lines=5),
|
185 |
+
gr.Textbox(label="Key Facts About Mineral", elem_id="mineral_key_facts", lines=8)
|
186 |
]
|
187 |
image_button = gr.Button("Classify Mineral")
|
188 |
image_button.click(classify_image, inputs=image_input, outputs=output_components)
|
189 |
+
|
190 |
+
with gr.Row():
|
191 |
+
gr.Textbox(label="Mineral Detection", elem_id="mineral_detection_output", lines=3)
|
192 |
+
gr.Textbox(label="Mineral Classification", elem_id="mineral_classification_output", lines=3)
|
193 |
+
gr.Textbox(label="Mineral Key Facts", elem_id="mineral_key_facts_output", lines=8)
|
194 |
+
gr.Examples(
|
195 |
+
examples=["Gradio examples/Biotite1.jpg","Gradio examples/Biotite2.jpg","Gradio examples/Olivine1.jpg","Gradio examples/Plagioclase1.jpg"],
|
196 |
+
inputs=image_input,
|
197 |
+
|
198 |
+
|
199 |
+
)
|
200 |
+
demo.launch( auth_message="Welcome To Mineral Identification App.")
|