Spaces:
Runtime error
Runtime error
import tensorflow as tf | |
from keras.models import load_model | |
import gradio as gr | |
from matplotlib import pyplot as plt | |
import cv2 | |
import numpy as np | |
model = load_model('eee4.keras') | |
def image_mod(image): | |
raw_image = image | |
temp_image = "temporary_image.jpg" | |
cv2.imwrite(temp_image, raw_image) | |
img = cv2.imread("temporary_image.jpg") | |
resize = tf.image.resize(img, (256, 256)) | |
plt.imshow(resize.numpy().astype(int)) | |
yhat = model.predict(np.expand_dims(resize,0)) | |
display_old = np.argmax(yhat) | |
display = str(display_old) | |
#display = str(yhat) | |
#display = str(display) | |
if display == "0": | |
message = "Cloudy" # | |
if display == "1": | |
message = "Snowy" # Morning_fog_-_Flickr_-_tmoravec.jpg | |
if display == "2": | |
message = "Foggy" # Stuyvesant_Fish_House_25_E78_St_cloudy_jeh.jpg | |
if display == "3": | |
message = "Rainy" #Snow_on_Branches,_Beechview,_2020-12-17,_01.jpg | |
if display == "4": | |
message = "Sunny" # Daedalus_000355_171913_516869_4578_(36155269413).jpg | |
return message | |
gr.Interface(fn=image_mod, | |
inputs=gr.Image(shape=(256, 256)), | |
outputs=gr.Label(num_top_classes=3), | |
examples=["640px-Hopetoun_house_sunny_day.jpg","Panoramic_of_water_reflection_of_the_mountains_of_Vang_Vieng_with_cloudy_sky_in_paddy_fields.jpg","Snow_Scene_at_Shipka_Pass_1.JPG","Jida,_Zhuhai,_rainy_day.jpg","The_lift_bridge_on_Cherry_Street_over_the_ship_channel_to_the_Turning_Basin_on_a_foggy_day,_2012-03-17_-a.jpg"]).launch() |