Spaces:
Sleeping
Sleeping
import numpy as np | |
import pandas as pd | |
import pickle | |
import datasets | |
from datasets import Dataset, DatasetDict | |
from six import BytesIO | |
import gradio as gr | |
from huggingface_hub import snapshot_download | |
import os | |
from matplotlib import pyplot as plt | |
import seaborn as sns | |
import torch | |
from neuralforecast import NeuralForecast | |
from neuralforecast.models import NBEATS | |
#PATH_TO_LABELS = 'label_map.pbtxt' | |
#category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True) | |
#def load_image_into_numpy_array(path): | |
# image = None | |
# image_data = tf.io.gfile.GFile(path, 'rb').read() | |
# image = Image.open(BytesIO(image_data)) | |
# return pil_image_as_numpy_array(image) | |
def load_model(): | |
download_dir = snapshot_download(REPO_ID) | |
saved_model_dir = os.path.join(download_dir, "saved_model") | |
futr_df = Dataset.from_pandas(futr_df) | |
prediction_model = NeuralForecast.load(saved_model_dir) | |
return prediction_model | |
# samples_folder = 'test_samples | |
# image_path = 'test_samples/sample_balloon.jpeg | |
# | |
#def predict(pilimg): | |
# image_np = pil_image_as_numpy_array(pilimg) | |
# return predict2(image_np) | |
#def predict2(image_np): | |
# results = detection_model(image_np) | |
# different object detection models have additional results | |
# result = {key:value.numpy() for key,value in results.items()} | |
# label_id_offset = 0 | |
# image_np_with_detections = image_np.copy() | |
# viz_utils.visualize_boxes_and_labels_on_image_array( | |
# image_np_with_detections[0], | |
# result['detection_boxes'][0], | |
# (result['detection_classes'][0] + label_id_offset).astype(int), | |
# result['detection_scores'][0], | |
# category_index, | |
# use_normalized_coordinates=True, | |
# max_boxes_to_draw=200, | |
# min_score_thresh=.60, | |
# agnostic_mode=False, | |
# line_thickness=2) | |
# result_pil_img = tf.keras.utils.array_to_img(image_np_with_detections[0]) | |
# return result_pil_img | |
REPO_ID = "magcheong/ITI110_Energy_Prediction" | |
prediction_model = load_model() | |
title = "testing" | |
description = "This is an app to detect burger and fries." | |
css_code = ".gradio-container {background: rgb(250, 250, 210)}" | |
# css_code='body{background-size: 25% 25%; background-repeat: no-repeat; background-image:url("https://static.vecteezy.com/system/resources/previews/022/787/250/original/illustration-of-french-fries-transparent-background-generative-ai-png.png");}' | |
gr.Interface(fn=predict, | |
title = title, | |
description = description, | |
css=css_code, | |
#inputs=gr.Image(type="pil", height=309), | |
#outputs=gr.Image(type="pil", height=350) | |
).launch(share=True) |