TeetouchQQ
commited on
Commit
•
a3cc822
1
Parent(s):
87f1936
Delete README.md
Browse files
README.md
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
|
3 |
-
#! pip install transformers -q
|
4 |
-
|
5 |
-
#! pip install gradio -q
|
6 |
-
|
7 |
-
from PIL import Image
|
8 |
-
from transformers import VisionEncoderDecoderModel, ViTFeatureExtractor, AutoTokenizer
|
9 |
-
import requests
|
10 |
-
|
11 |
-
model = VisionEncoderDecoderModel.from_pretrained("TeetouchQQ/Food-caption")
|
12 |
-
vit_feature_extractor = ViTFeatureExtractor.from_pretrained("microsoft/swin-base-patch4-window7-224")
|
13 |
-
tokenizer = AutoTokenizer.from_pretrained("bert-base-multilingual-cased")
|
14 |
-
|
15 |
-
|
16 |
-
def vit2distilgpt2(img):
|
17 |
-
pixel_values = vit_feature_extractor(images=img, return_tensors="pt").pixel_values
|
18 |
-
encoder_outputs = generated_ids = model.generate(pixel_values.to('cpu'),num_beams=5)
|
19 |
-
generated_sentences = tokenizer.batch_decode(encoder_outputs, skip_special_tokens=True)
|
20 |
-
|
21 |
-
return(generated_sentences[0].split('.')[0])
|
22 |
-
|
23 |
-
#!wget https://media.glamour.com/photos/5f171c4fd35176eaedb36823/master/w_2560%2Cc_limit/bike.jpg
|
24 |
-
|
25 |
-
import gradio as gr
|
26 |
-
|
27 |
-
inputs = [
|
28 |
-
gr.inputs.Image(type="pil", label="Original Image")
|
29 |
-
]
|
30 |
-
|
31 |
-
outputs = [
|
32 |
-
gr.outputs.Textbox(label = 'Caption')
|
33 |
-
]
|
34 |
-
|
35 |
-
title = "Food Captioning using Swin + Bert"
|
36 |
-
|
37 |
-
gr.Interface(
|
38 |
-
vit2distilgpt2,
|
39 |
-
inputs,
|
40 |
-
outputs,
|
41 |
-
title=title,
|
42 |
-
description=description,
|
43 |
-
article=article,
|
44 |
-
theme="huggingface",
|
45 |
-
).launch(debug=True, enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|