jaekookang commited on
Commit
eb6c57c
โ€ข
1 Parent(s): 0d8626e

test gradio template with image examples

Browse files
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
- def greet(name):
8
- logger.info('name received')
9
- return "hello " + name + "!!"
 
 
 
 
 
 
 
 
 
10
 
11
 
12
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
13
- iface.launch()
 
 
 
 
 
 
 
 
 
 
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