dpmodels / app.py
Kushalgeesawor's picture
Update app.py
3ed8d08
# -*- coding: utf-8 -*-
"""app.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1CcqIRPpKj7PeOmrdGk-dDPxPVgwkM4i8
"""
#!git clone https://huggingface.co/spaces/Kushalgeesawor/dpmodels
#!pip install gradio
#!pip install fastai
import os
os.system('pip install rembg')
os.system('pip install google-colab')
from fastai.vision.all import *
import gradio as gr
from google.colab import files as FILE
import os
import requests
img_data = gr.inputs.Image(source='webcam', tool='streaming', label='image')
with open('input.jpg', 'wb') as handler:
handler.write(img_data)
os.system('rembg i input.jpg image1_output_bg.jpg')
learn = load_learner('gemstonemodel_paperspace01.pkl')
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
#iface = gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3))
#iface = gr.Interface(fn=predict, inputs=gr.inputs.Image(source=webcam, streaming=True),"image", live=True, outputs=gr.outputs.Label(num_top_classes=3))
iface = gr.Interface(
fn=predict,
inputs=image1_output_bg.jpg,
outputs=gr.outputs.Label(num_top_classes=3),
live=True
)
iface.launch()
#!gradio deploy
#!git config --global credential.helper store
#!gradio deploy
#import os
#os.chdir('dpmodels')
#!git add *
#!git commit -m 'update'
#!git push