Spaces:
Sleeping
Sleeping
NickNYU
commited on
Commit
Β·
30c0ce1
1
Parent(s):
88a169e
local runtime ok
Browse files- app.py +14 -23
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
-
import torch
|
2 |
-
import re
|
3 |
import gradio as gr
|
4 |
-
from PIL import Image
|
5 |
|
6 |
-
from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
7 |
import os
|
8 |
-
|
9 |
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
10 |
|
11 |
-
device='cpu'
|
|
|
12 |
|
13 |
model_id = "nttdataspain/vit-gpt2-stablediffusion2-lora"
|
14 |
model = VisionEncoderDecoderModel.from_pretrained(model_id)
|
@@ -27,18 +26,15 @@ def predict(image):
|
|
27 |
preds = [pred.strip() for pred in preds]
|
28 |
return preds[0]
|
29 |
|
30 |
-
input = gr.inputs.Image(label="Upload any Image", type = 'pil', optional=True)
|
31 |
-
output = gr.outputs.Textbox(type="text",label="Captions")
|
32 |
examples_folder = os.path.join(os.path.dirname(__file__), "examples")
|
33 |
examples = [os.path.join(examples_folder, file) for file in os.listdir(examples_folder)]
|
34 |
|
35 |
with gr.Blocks() as demo:
|
36 |
-
|
37 |
gr.HTML(
|
38 |
"""
|
39 |
<div style="text-align: center; max-width: 1200px; margin: 20px auto;">
|
40 |
<h2 style="font-weight: 900; font-size: 3rem; margin: 0rem">
|
41 |
-
πΈ
|
42 |
</h2>
|
43 |
<h2 style="text-align: left; font-weight: 450; font-size: 1rem; margin-top: 2rem; margin-bottom: 1.5rem">
|
44 |
In the field of large language models, the challenge of fine-tuning has long perplexed researchers. Microsoft, however, has unveiled an innovative solution called <b>Low-Rank Adaptation (LoRA)</b>. With the emergence of behemoth models like GPT-3 boasting billions of parameters, the cost of fine-tuning them for specific tasks or domains has become exorbitant.
|
@@ -48,21 +44,16 @@ with gr.Blocks() as demo:
|
|
48 |
</h2>
|
49 |
</div>
|
50 |
""")
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
with gr.Column(scale=1):
|
57 |
-
out = gr.outputs.Textbox(type="text",label="Captions")
|
58 |
-
|
59 |
button.click(predict, inputs=[img], outputs=[out])
|
60 |
-
|
61 |
-
gr.
|
62 |
-
examples=examples,
|
63 |
inputs=img,
|
64 |
outputs=out,
|
65 |
fn=predict,
|
66 |
-
cache_examples=True,
|
67 |
)
|
68 |
-
demo.launch(debug=True)
|
|
|
1 |
+
import torch
|
|
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
5 |
import os
|
6 |
+
|
7 |
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
8 |
|
9 |
+
device = 'cpu'
|
10 |
+
|
11 |
|
12 |
model_id = "nttdataspain/vit-gpt2-stablediffusion2-lora"
|
13 |
model = VisionEncoderDecoderModel.from_pretrained(model_id)
|
|
|
26 |
preds = [pred.strip() for pred in preds]
|
27 |
return preds[0]
|
28 |
|
|
|
|
|
29 |
examples_folder = os.path.join(os.path.dirname(__file__), "examples")
|
30 |
examples = [os.path.join(examples_folder, file) for file in os.listdir(examples_folder)]
|
31 |
|
32 |
with gr.Blocks() as demo:
|
|
|
33 |
gr.HTML(
|
34 |
"""
|
35 |
<div style="text-align: center; max-width: 1200px; margin: 20px auto;">
|
36 |
<h2 style="font-weight: 900; font-size: 3rem; margin: 0rem">
|
37 |
+
πΈ Video Image Info with LORA π
|
38 |
</h2>
|
39 |
<h2 style="text-align: left; font-weight: 450; font-size: 1rem; margin-top: 2rem; margin-bottom: 1.5rem">
|
40 |
In the field of large language models, the challenge of fine-tuning has long perplexed researchers. Microsoft, however, has unveiled an innovative solution called <b>Low-Rank Adaptation (LoRA)</b>. With the emergence of behemoth models like GPT-3 boasting billions of parameters, the cost of fine-tuning them for specific tasks or domains has become exorbitant.
|
|
|
44 |
</h2>
|
45 |
</div>
|
46 |
""")
|
47 |
+
|
48 |
+
img = gr.Image(label="Upload any Image", type='pil')
|
49 |
+
button = gr.Button(value="Describe")
|
50 |
+
out = gr.Textbox(type="text", label="Captions")
|
51 |
+
|
|
|
|
|
|
|
52 |
button.click(predict, inputs=[img], outputs=[out])
|
53 |
+
|
54 |
+
gr.Interface(
|
|
|
55 |
inputs=img,
|
56 |
outputs=out,
|
57 |
fn=predict,
|
|
|
58 |
)
|
59 |
+
demo.launch(debug=True)
|
requirements.txt
CHANGED
@@ -4,4 +4,4 @@ pillow
|
|
4 |
requests
|
5 |
torch
|
6 |
tensorflow
|
7 |
-
gradio ==
|
|
|
4 |
requests
|
5 |
torch
|
6 |
tensorflow
|
7 |
+
gradio == 4.29
|