Imadsarvm commited on
Commit
5b44f43
1 Parent(s): 7c31dd9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import gradio as gr
3
+ import os
4
+ import functools
5
+ from PIL import Image
6
+ from rembg import remove
7
+ from io import BytesIO
8
+ import numpy as np
9
+ import torch
10
+ from torch.autograd import Variable
11
+ from torchvision import transforms
12
+ import torch.nn.functional as F
13
+ import gdown
14
+ import matplotlib.pyplot as plt
15
+ import warnings
16
+ warnings.filterwarnings("ignore")
17
+ import requests
18
+
19
+ @functools.lru_cache()
20
+ def get_url_im(t):
21
+ user_agent = {'User-agent': 'gradio-app'}
22
+ response = requests.get(t, headers=user_agent)
23
+ return (BytesIO(response.content))
24
+
25
+
26
+ def inference(image):
27
+ im_path = get_url_im(image)
28
+ im = Image.open(im_reader(im_path))
29
+
30
+
31
+ return im, im , im
32
+
33
+
34
+
35
+
36
+ interface = gr.Interface(
37
+ fn=inference,
38
+ inputs=gr.Textbox(label="Text or Image URL", interactive=True),
39
+ outputs=["image","image","image"],
40
+ title=title,
41
+ description=description,
42
+ article=article,
43
+ allow_flagging='never',
44
+ cache_examples=False,
45
+ ).queue().launch(show_error=True, share = True)