DemahAlmutairi commited on
Commit
cfdf2e8
·
verified ·
1 Parent(s): 78b4a3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py CHANGED
@@ -41,7 +41,83 @@ def tabs_select(e: gr.SelectData, _state):
41
  example_img_paths = [["https://4.img-dpreview.com/files/p/E~TS590x0~articles/3925134721/0266554465.jpeg"],
42
  ["https://images4.alphacoders.com/688/688832.jpg"]]
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  with gr.Blocks() as iface:
46
  gr.HTML("""<p align="center"><img src="https://cdn-icons-png.flaticon.com/512/5853/5853758.png" style="height: 60px"/><p>""")
47
  gr.HTML("""<center><font size=8>Image Captioning Demo</center>""")
 
41
  example_img_paths = [["https://4.img-dpreview.com/files/p/E~TS590x0~articles/3925134721/0266554465.jpeg"],
42
  ["https://images4.alphacoders.com/688/688832.jpg"]]
43
 
44
+
45
+ css_code = """
46
+ <style>
47
+ body {
48
+ font-family: Arial, sans-serif;
49
+ background-color: #f4f4f4;
50
+ margin: 0;
51
+ padding: 20px;
52
+ }
53
+ h1 {
54
+ font-size: 2.5em;
55
+ color: #333;
56
+ text-align: center;
57
+ }
58
+ p {
59
+ color: #666;
60
+ text-align: center;
61
+ margin: 10px 0;
62
+ }
63
+ #examples_row {
64
+ margin-top: 20px;
65
+ justify-content: center;
66
+ }
67
+ .gr-button {
68
+ background-color: #007bff;
69
+ color: white;
70
+ border-radius: 5px;
71
+ border: none;
72
+ padding: 10px 20px;
73
+ margin: 5px;
74
+ cursor: pointer;
75
+ }
76
+ .gr-button:hover {
77
+ background-color: #0056b3;
78
+ }
79
+ .gr-button:focus {
80
+ outline: none;
81
+ }
82
+ </style>
83
+ """
84
+
85
+ with gr.Blocks(css=css_code) as iface:
86
+ gr.HTML("""<p align="center"><img src="https://cdn-icons-png.flaticon.com/512/5853/5853758.png" style="height: 60px"/><p>""")
87
+ gr.HTML("""<h1>Image Captioning Demo</h1>""")
88
+ gr.HTML("""<p>In this space you can input either an image or draw a sketch of an object to receive an Arabic caption.</p>""")
89
+
90
+ state = gr.State({"tab_index": 0})
91
 
92
+ with gr.Row():
93
+ with gr.Column():
94
+ with gr.Tabs() as input_tabs:
95
+ with gr.Tab("Upload"):
96
+ input_image = gr.Image(type="pil", label="Upload")
97
+ with gr.Tab("Sketch"):
98
+ input_sketchpad = gr.Sketchpad(type="pil", label="Sketch", layers=False)
99
+ input_tabs.select(fn=tabs_select, inputs=[state])
100
+
101
+ with gr.Row(elem_id="examples_row"):
102
+ with gr.Column(elem_id="examples_container"):
103
+ gr.Markdown("### Example Prompts")
104
+ gr.Examples(
105
+ example_img_paths,
106
+ inputs=[input_image],
107
+ cache_examples=False
108
+ )
109
+
110
+ with gr.Row():
111
+ with gr.Column():
112
+ clear_btn = gr.ClearButton(
113
+ [input_image, input_sketchpad])
114
+ with gr.Column():
115
+ submit_btn = gr.Button("Submit", variant="primary")
116
+ submit_btn.click(
117
+ fn=parse_input,
118
+ inputs=[input_image, input_sketchpad, state],
119
+ outputs=[gr.Textbox(label="English Result"), gr.Textbox(label="Arabic Result")]
120
+ )
121
  with gr.Blocks() as iface:
122
  gr.HTML("""<p align="center"><img src="https://cdn-icons-png.flaticon.com/512/5853/5853758.png" style="height: 60px"/><p>""")
123
  gr.HTML("""<center><font size=8>Image Captioning Demo</center>""")