File size: 998 Bytes
5b44f43 |
1 2 3 4 5 6 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 37 38 39 40 41 42 43 44 45 |
import cv2
import gradio as gr
import os
import functools
from PIL import Image
from rembg import remove
from io import BytesIO
import numpy as np
import torch
from torch.autograd import Variable
from torchvision import transforms
import torch.nn.functional as F
import gdown
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")
import requests
@functools.lru_cache()
def get_url_im(t):
user_agent = {'User-agent': 'gradio-app'}
response = requests.get(t, headers=user_agent)
return (BytesIO(response.content))
def inference(image):
im_path = get_url_im(image)
im = Image.open(im_reader(im_path))
return im, im , im
interface = gr.Interface(
fn=inference,
inputs=gr.Textbox(label="Text or Image URL", interactive=True),
outputs=["image","image","image"],
title=title,
description=description,
article=article,
allow_flagging='never',
cache_examples=False,
).queue().launch(show_error=True, share = True) |