Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
from tensorflow.keras.models import load_model
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
if uploaded_image:
|
37 |
-
st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
38 |
-
|
39 |
-
# Load model
|
40 |
-
with st.spinner("Loading model..."):
|
41 |
-
model = load_model_from_huggingface()
|
42 |
-
|
43 |
-
# Preprocess image
|
44 |
-
image = Image.open(uploaded_image)
|
45 |
-
preprocessed_image = preprocess_image(image)
|
46 |
-
|
47 |
-
# Predict severity
|
48 |
-
with st.spinner("Predicting severity..."):
|
49 |
-
predicted_class, prediction_scores = predict_severity(model, preprocessed_image)
|
50 |
-
|
51 |
-
# Display results
|
52 |
-
st.success(f"Predicted Class: {predicted_class}")
|
53 |
-
st.write("Prediction Scores:")
|
54 |
-
for class_name, score in zip(['0', 'MR', 'MRMS', 'MS', 'R', 'S'], prediction_scores[0]):
|
55 |
-
st.write(f"{class_name}: {score:.4f}")
|
|
|
1 |
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
|
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
# Load environment variables
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
# Load Hugging Face model
|
12 |
+
model_url = os.getenv('HUGGINGFACE_MODEL_URL')
|
13 |
+
model = torch.hub.load(model_url, 'model', source='hf')
|
14 |
+
|
15 |
+
# Setup Streamlit
|
16 |
+
st.title('Yellow Rust Severity Prediction')
|
17 |
+
|
18 |
+
# File uploader
|
19 |
+
uploaded_file = st.file_uploader("Upload an image of Yellow Rust", type=["jpg", "png"])
|
20 |
+
|
21 |
+
if uploaded_file is not None:
|
22 |
+
# Display the uploaded image
|
23 |
+
image = Image.open(uploaded_file)
|
24 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
25 |
+
|
26 |
+
# Process the image and make prediction
|
27 |
+
classifier = pipeline('image-classification', model=model_url)
|
28 |
+
results = classifier(image)
|
29 |
+
|
30 |
+
severity_level = results[0]['label']
|
31 |
+
confidence = results[0]['score']
|
32 |
+
|
33 |
+
st.write(f"Predicted Severity Level: {severity_level} with confidence: {confidence:.2f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|