soteria-ml / app.py
SamT6
model from aws
3e2d424
raw history blame
No virus
1.88 kB
import gradio as gr
from matplotlib.pyplot import title
import numpy as np
import tensorflow as tf
import random
from tensorflow import keras
from cloudpathlib import CloudPath
cp = CloudPath("s3://soteria-ml-models/")
cp.download_to("./models")
damage_types = np.array(sorted(['disaster happened', 'no disaster happened']))
disaster_types = np.array(sorted(['volcano', 'flooding', 'earthquake', 'fire', 'wind', 'tsunami']))
model = keras.models.load_model('./models/disaster-classification')
def damage_classification(img):
prediction = np.random.rand(1, 2)[0]
return {damage_types[i]: prediction[i] for i in range(len(damage_types))}
def disaster_classification(img):
image = np.zeros((1, 1024, 1024, 3), dtype=np.uint8)
image[0] = img
prediction = model.predict(image).tolist()[0]
# prediction = np.random.rand(1, 6)[0]
return {disaster_types[i]: prediction[i] for i in range(len(disaster_types))}
iface = gr.Interface(
fn = [damage_classification, disaster_classification],
inputs = gr.inputs.Image(shape=(1024, 1024), image_mode='RGB', invert_colors=False, source="upload", type='numpy'),
outputs = gr.outputs.Label(),
allow_screenshot=True,
allow_flagging='never',
examples=[
'./sample_images/hurricane.png',
'./sample_images/volcano.png',
'./sample_images/wildfire.png'
],
thumbnail='./soteria-logo.png',
title="Soteria - AI for Natural Disaster Response",
description="""
Check out our project @ https://github.com/Soteria-ai/Soteria, see below for more explantation!
""",
theme="grass",
article="""
Explantation
Model #1 - Damage Classification: weather a diasater has happened or not
Model #2 - Disaster Classificaiton: what type of disaster happened?
"""
)
iface.launch(share=False, show_error=True, inline=True, debug=True)