Spaces:
Runtime error
Runtime error
jaekookang
commited on
Commit
โข
eb6c57c
1
Parent(s):
0d8626e
test gradio template with image examples
Browse files- examples/land1.jpg +0 -0
- examples/land2.jpg +0 -0
- examples/land3.jpg +0 -0
- examples/plot1.jpg +0 -0
- examples/plot2.jpg +0 -0
- gradio_imagecompletion.py +43 -5
- igpt-xl-miscellaneous-2-orig.png +0 -0
- igpt-xl-miscellaneous-29-orig.png +0 -0
examples/land1.jpg
ADDED
examples/land2.jpg
ADDED
examples/land3.jpg
ADDED
examples/plot1.jpg
ADDED
examples/plot2.jpg
ADDED
gradio_imagecompletion.py
CHANGED
@@ -1,13 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from loguru import logger
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
logger.add('app.log', mode='a')
|
5 |
logger.info('===== APP RESTARTED =====')
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
-
iface = gr.Interface(
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'''Image Completion Demo (ImageGPT)
|
2 |
+
|
3 |
+
- 2021-12-10
|
4 |
+
- taken from https://huggingface.co/spaces/nielsr/imagegpt-completion
|
5 |
+
'''
|
6 |
+
|
7 |
+
from PIL import Image
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
|
10 |
+
import os
|
11 |
+
import requests
|
12 |
+
from glob import glob
|
13 |
import gradio as gr
|
14 |
from loguru import logger
|
15 |
|
16 |
+
import torch
|
17 |
+
from transformers import ImageGPTFeatureExtractor, ImageGPTForCausalImageModeling
|
18 |
+
|
19 |
+
# ========== Settings ==========
|
20 |
+
EXAMPLE_DIR = 'examples'
|
21 |
+
examples = sorted(glob(os.path.join(EXAMPLE_DIR, '*.jpg')))
|
22 |
+
|
23 |
+
# ========== Logger ==========
|
24 |
logger.add('app.log', mode='a')
|
25 |
logger.info('===== APP RESTARTED =====')
|
26 |
|
27 |
+
# ========== Models ==========
|
28 |
+
feature_extractor = ImageGPTFeatureExtractor.from_pretrained(
|
29 |
+
"openai/imagegpt-medium")
|
30 |
+
model = ImageGPTForCausalImageModeling.from_pretrained(
|
31 |
+
"openai/imagegpt-medium")
|
32 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
33 |
+
model.to(device)
|
34 |
+
|
35 |
+
|
36 |
+
def process_image(image):
|
37 |
+
logger.info('--- image file received')
|
38 |
+
return image.name
|
39 |
|
40 |
|
41 |
+
iface = gr.Interface(
|
42 |
+
process_image,
|
43 |
+
title="์ด๋ฏธ์ง์ ์ ๋ฐ์ ์ง์ฐ๊ณ ์ ๋ฐ์ ์ฑ์ ๋ฃ์ด์ฃผ๋ Image Completion ๋ฐ๋ชจ์
๋๋ค (ImageGPT)",
|
44 |
+
description='์ฃผ์ด์ง ์ด๋ฏธ์ง์ ์ ๋ฐ ์๋๋ฅผ AI๊ฐ ์ฑ์ ๋ฃ์ด์ค๋๋ค',
|
45 |
+
inputs=gr.inputs.Image(type="pil"),
|
46 |
+
outputs=gr.outputs.Image(type="pil", label="Model input + completions"),
|
47 |
+
examples=examples,
|
48 |
+
enable_queue=True,
|
49 |
+
article='<p style="text-align:center">i-Scream AI</p>',
|
50 |
+
)
|
51 |
+
iface.launch()
|
igpt-xl-miscellaneous-2-orig.png
ADDED
igpt-xl-miscellaneous-29-orig.png
ADDED