Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,29 @@ import gradio as gr
|
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
from model import CaptioningTransformer
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
image_size = 128
|
| 10 |
patch_size = 8
|
|
@@ -63,9 +86,12 @@ def predict(image: Image.Image):
|
|
| 63 |
return caption
|
| 64 |
|
| 65 |
|
| 66 |
-
with gr.Blocks(css=
|
| 67 |
-
gr.
|
| 68 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
|
@@ -78,7 +104,7 @@ with gr.Blocks(css=".block-title { font-size: 48px; font-weight: bold; }") as de
|
|
| 78 |
)
|
| 79 |
|
| 80 |
generate_button.click(fn=predict, inputs=image_input, outputs=caption_output)
|
| 81 |
-
|
| 82 |
|
| 83 |
if __name__ == "__main__":
|
| 84 |
demo.launch(share=True)
|
|
|
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
from model import CaptioningTransformer
|
| 7 |
|
| 8 |
+
css_str = """
|
| 9 |
+
body {
|
| 10 |
+
background-color: #121212;
|
| 11 |
+
color: #e0e0e0;
|
| 12 |
+
font-family: Arial, sans-serif;
|
| 13 |
+
}
|
| 14 |
+
.container {
|
| 15 |
+
max-width: 700px;
|
| 16 |
+
margin: 15px auto;
|
| 17 |
+
}
|
| 18 |
+
h1 {
|
| 19 |
+
font-size: 36px;
|
| 20 |
+
font-weight: bold;
|
| 21 |
+
text-align: center;
|
| 22 |
+
color: #ffffff;
|
| 23 |
+
}
|
| 24 |
+
.description {
|
| 25 |
+
font-size: 18px;
|
| 26 |
+
text-align: center;
|
| 27 |
+
color: #b0b0b0;
|
| 28 |
+
}
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 32 |
image_size = 128
|
| 33 |
patch_size = 8
|
|
|
|
| 86 |
return caption
|
| 87 |
|
| 88 |
|
| 89 |
+
with gr.Blocks(css=css_str) as demo:
|
| 90 |
+
gr.HTML("<div class='container'>")
|
| 91 |
+
gr.Markdown("<h1>Image Captioning</h1>")
|
| 92 |
+
gr.Markdown(
|
| 93 |
+
"<div class='description'>Upload an image and get a descriptive caption about the image:</div>"
|
| 94 |
+
)
|
| 95 |
|
| 96 |
with gr.Row():
|
| 97 |
with gr.Column():
|
|
|
|
| 104 |
)
|
| 105 |
|
| 106 |
generate_button.click(fn=predict, inputs=image_input, outputs=caption_output)
|
| 107 |
+
gr.HTML("</div>")
|
| 108 |
|
| 109 |
if __name__ == "__main__":
|
| 110 |
demo.launch(share=True)
|