Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,3 @@
|
|
| 1 |
-
Apologies for the breakup! Hereโs the complete, unbroken code listing for app.py, incorporating the Gradio 5.23.0 features demo without the accept parameter, all in one cohesive block:
|
| 2 |
-
|
| 3 |
-
python
|
| 4 |
-
|
| 5 |
-
Collapse
|
| 6 |
-
|
| 7 |
-
Wrap
|
| 8 |
-
|
| 9 |
-
Copy
|
| 10 |
-
#!/usr/bin/env python3
|
| 11 |
# ๐ Shebanginโ it like itโs 1999โPython 3, letโs roll!
|
| 12 |
|
| 13 |
# ๐งณ Importing the whole circusโget ready for a wild ride!
|
|
@@ -130,68 +120,70 @@ def get_dataframe():
|
|
| 130 |
|
| 131 |
# ๐ Mermaid.js demoโflowchart fun from 5.23.0!
|
| 132 |
def get_mermaid_chart():
|
| 133 |
-
return """
|
| 134 |
-
```mermaid
|
| 135 |
graph TD
|
| 136 |
A[Upload Files] --> B[View Gallery]
|
| 137 |
B --> C[Select Files]
|
| 138 |
C --> D[Generate Output]
|
| 139 |
D --> E[Deep Link to Result]
|
| 140 |
-
"""
|
| 141 |
|
| 142 |
-
๐จ Code editor demoโJedi completion from 5.23.0!
|
| 143 |
def get_code_snippet():
|
| 144 |
return "def hello(name):\n return f'Hello, {name}!'"
|
| 145 |
|
| 146 |
-
๐ช Gradio UIโstep right up to the AI circus!
|
| 147 |
with gr.Blocks(title="Gradio 5.23.0 Mastery Demo ๐") as demo:
|
| 148 |
gr.Markdown(f"# Gradio 5.23.0 Mastery Demo ๐\nRunning Gradio version: {pkg_resources.get_distribution('gradio').version}") # ๐ Welcome to the big top with version check!
|
| 149 |
history = gr.State(value=[]) # ๐ The ringmasterโs logbook!
|
| 150 |
selected_files = gr.State(value={}) # โ
The chosen ones, ready to perform!
|
| 151 |
|
| 152 |
with gr.Row():
|
| 153 |
-
with gr.Column(scale=1):
|
| 154 |
-
gr.Markdown("## ๐ Files") # ๐๏ธ The file circus tent!
|
| 155 |
-
sidebar_files = gr.Files(label="Downloads", height=300) # ๐ฅ Grab your souvenirs here!
|
| 156 |
|
| 157 |
with gr.Column(scale=3):
|
| 158 |
-
with gr.Row():
|
| 159 |
-
gr.Markdown("## ๐ ๏ธ Toolbar") # ๐ง The circus control panel!
|
| 160 |
-
select_btn = gr.Button("โ
Select") # โ
Pick your performers!
|
| 161 |
|
| 162 |
with gr.Tabs():
|
| 163 |
-
with gr.TabItem("๐ค Upload"): # ๐ค The upload trapeze!
|
| 164 |
-
with gr.Row():
|
| 165 |
-
img_upload = gr.File(label="๐ผ๏ธ Images (jpg/png)", file_count="multiple") # ๐ผ๏ธ Picture trapeze!
|
| 166 |
-
doc_upload = gr.File(label="๐ Docs (pdf)", file_count="multiple") # ๐ Doc drop!
|
| 167 |
-
with gr.Row():
|
| 168 |
-
data_upload = gr.File(label="๐ Data (csv)", file_count="multiple") # ๐ Data dive!
|
| 169 |
-
upload_status = gr.Textbox(label="Status") # ๐ข Ringmasterโs update!
|
| 170 |
-
gr.Button("๐ค Upload Images").click(upload_images, inputs=[img_upload, history, selected_files], outputs=[upload_status, history, selected_files]).then(update_galleries, inputs=[history, selected_files], outputs=[gr.Gallery(), gr.Gallery(), gr.Gallery(), history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 171 |
-
gr.Button("๐ค Upload Docs").click(upload_documents, inputs=[doc_upload, history, selected_files], outputs=[upload_status, history, selected_files]).then(update_galleries, inputs=[history, selected_files], outputs=[gr.Gallery(), gr.Gallery(), gr.Gallery(), history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 172 |
-
gr.Button("๐ค Upload Data").click(upload_datasets, inputs=[data_upload, history, selected_files], outputs=[upload_status, history, selected_files]).then(update_galleries, inputs=[history, selected_files], outputs=[gr.Gallery(), gr.Gallery(), gr.Gallery(), history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 173 |
|
| 174 |
with gr.TabItem("๐ผ๏ธ Gallery"): # ๐ผ๏ธ The big top showcase!
|
| 175 |
-
img_gallery = gr.Gallery(label="๐ผ๏ธ Images (jpg/png)", columns=4, height="auto") # ๐ผ๏ธ Picture parade!
|
| 176 |
-
doc_gallery = gr.Gallery(label="๐ Docs (pdf)", columns=4, height="auto") # ๐ Doc depot!
|
| 177 |
-
data_gallery = gr.Gallery(label="๐ Data (csv)", columns=4, height="auto") # ๐ Data den!
|
| 178 |
-
gr.Button("๐ Refresh").click(update_galleries, inputs=[history, selected_files], outputs=[img_gallery, doc_gallery, data_gallery, history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 179 |
|
| 180 |
with gr.TabItem("๐ Features"): # ๐ The magic trick tent!
|
| 181 |
-
gr.Markdown("### ๐ Dataframe Mastery (5.21.0)") # ๐ Flexing new dataframe tricks!
|
| 182 |
-
df_output = gr.Dataframe(value=get_dataframe, interactive=True, static_columns=["Name"], wrap=True) # ๐ฅ Static columns, drag selection from 5.21.0!
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
gr.Markdown(
|
| 186 |
-
|
| 187 |
-
gr.Markdown("###
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
| 194 |
demo.load(lambda h: "\n".join(h[-5:]), inputs=[history], outputs=[history_output])
|
| 195 |
|
| 196 |
-
๐ Launch the circusโstep right up, folks!
|
| 197 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# ๐ Shebanginโ it like itโs 1999โPython 3, letโs roll!
|
| 2 |
|
| 3 |
# ๐งณ Importing the whole circusโget ready for a wild ride!
|
|
|
|
| 120 |
|
| 121 |
# ๐ Mermaid.js demoโflowchart fun from 5.23.0!
|
| 122 |
def get_mermaid_chart():
|
| 123 |
+
return """```mermaid
|
|
|
|
| 124 |
graph TD
|
| 125 |
A[Upload Files] --> B[View Gallery]
|
| 126 |
B --> C[Select Files]
|
| 127 |
C --> D[Generate Output]
|
| 128 |
D --> E[Deep Link to Result]
|
| 129 |
+
```"""
|
| 130 |
|
| 131 |
+
# ๐จ Code editor demoโJedi completion from 5.23.0!
|
| 132 |
def get_code_snippet():
|
| 133 |
return "def hello(name):\n return f'Hello, {name}!'"
|
| 134 |
|
| 135 |
+
# ๐ช Gradio UIโstep right up to the AI circus!
|
| 136 |
with gr.Blocks(title="Gradio 5.23.0 Mastery Demo ๐") as demo:
|
| 137 |
gr.Markdown(f"# Gradio 5.23.0 Mastery Demo ๐\nRunning Gradio version: {pkg_resources.get_distribution('gradio').version}") # ๐ Welcome to the big top with version check!
|
| 138 |
history = gr.State(value=[]) # ๐ The ringmasterโs logbook!
|
| 139 |
selected_files = gr.State(value={}) # โ
The chosen ones, ready to perform!
|
| 140 |
|
| 141 |
with gr.Row():
|
| 142 |
+
with gr.Column(scale=1):
|
| 143 |
+
gr.Markdown("## ๐ Files") # ๐๏ธ The file circus tent!
|
| 144 |
+
sidebar_files = gr.Files(label="Downloads", height=300) # ๐ฅ Grab your souvenirs here!
|
| 145 |
|
| 146 |
with gr.Column(scale=3):
|
| 147 |
+
with gr.Row():
|
| 148 |
+
gr.Markdown("## ๐ ๏ธ Toolbar") # ๐ง The circus control panel!
|
| 149 |
+
select_btn = gr.Button("โ
Select") # โ
Pick your performers!
|
| 150 |
|
| 151 |
with gr.Tabs():
|
| 152 |
+
with gr.TabItem("๐ค Upload"): # ๐ค The upload trapeze!
|
| 153 |
+
with gr.Row():
|
| 154 |
+
img_upload = gr.File(label="๐ผ๏ธ Images (jpg/png)", file_count="multiple") # ๐ผ๏ธ Picture trapeze!
|
| 155 |
+
doc_upload = gr.File(label="๐ Docs (pdf)", file_count="multiple") # ๐ Doc drop!
|
| 156 |
+
with gr.Row():
|
| 157 |
+
data_upload = gr.File(label="๐ Data (csv)", file_count="multiple") # ๐ Data dive!
|
| 158 |
+
upload_status = gr.Textbox(label="Status") # ๐ข Ringmasterโs update!
|
| 159 |
+
gr.Button("๐ค Upload Images").click(upload_images, inputs=[img_upload, history, selected_files], outputs=[upload_status, history, selected_files]).then(update_galleries, inputs=[history, selected_files], outputs=[gr.Gallery(), gr.Gallery(), gr.Gallery(), history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 160 |
+
gr.Button("๐ค Upload Docs").click(upload_documents, inputs=[doc_upload, history, selected_files], outputs=[upload_status, history, selected_files]).then(update_galleries, inputs=[history, selected_files], outputs=[gr.Gallery(), gr.Gallery(), gr.Gallery(), history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 161 |
+
gr.Button("๐ค Upload Data").click(upload_datasets, inputs=[data_upload, history, selected_files], outputs=[upload_status, history, selected_files]).then(update_galleries, inputs=[history, selected_files], outputs=[gr.Gallery(), gr.Gallery(), gr.Gallery(), history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 162 |
|
| 163 |
with gr.TabItem("๐ผ๏ธ Gallery"): # ๐ผ๏ธ The big top showcase!
|
| 164 |
+
img_gallery = gr.Gallery(label="๐ผ๏ธ Images (jpg/png)", columns=4, height="auto") # ๐ผ๏ธ Picture parade!
|
| 165 |
+
doc_gallery = gr.Gallery(label="๐ Docs (pdf)", columns=4, height="auto") # ๐ Doc depot!
|
| 166 |
+
data_gallery = gr.Gallery(label="๐ Data (csv)", columns=4, height="auto") # ๐ Data den!
|
| 167 |
+
gr.Button("๐ Refresh").click(update_galleries, inputs=[history, selected_files], outputs=[img_gallery, doc_gallery, data_gallery, history, selected_files]).then(update_sidebar, inputs=[history, selected_files], outputs=[sidebar_files, history])
|
| 168 |
|
| 169 |
with gr.TabItem("๐ Features"): # ๐ The magic trick tent!
|
| 170 |
+
gr.Markdown("### ๐ Dataframe Mastery (5.21.0)") # ๐ Flexing new dataframe tricks!
|
| 171 |
+
df_output = gr.Dataframe(value=get_dataframe, interactive=True, static_columns=["Name"], wrap=True) # ๐ฅ Static columns, drag selection from 5.21.0!
|
| 172 |
+
|
| 173 |
+
gr.Markdown("### ๐ Mermaid.js Flowchart (5.23.0)") # ๐ Mermaid.js from 5.23.0!
|
| 174 |
+
mermaid_output = gr.Markdown(value=get_mermaid_chart) # ๐ Flowchart fun!
|
| 175 |
+
|
| 176 |
+
gr.Markdown("### ๐จ Code Editor with Jedi Completion (5.23.0)") # ๐จ Jedi power from 5.23.0!
|
| 177 |
+
code_output = gr.Code(value=get_code_snippet, language="python", interactive=True) # โ๏ธ Code with autocompletion!
|
| 178 |
+
|
| 179 |
+
gr.Markdown("### ๐ฅ Deep Link Button (5.23.0)") # ๐ฅ Deep links from 5.23.0!
|
| 180 |
+
DeepLinkButton(label="Link to Latest Output", variant="secondary", deep_link="/gallery/images") # ๐ฅ Secondary variant from 5.23.0!
|
| 181 |
+
|
| 182 |
+
with gr.TabItem("๐ History"): # ๐ The logbook showcase!
|
| 183 |
+
history_output = gr.Textbox(label="History", lines=5, value="\n".join(history.value), interactive=False) # ๐ Whatโs been cooking?
|
| 184 |
+
|
| 185 |
+
# ๐ Auto-update history on loadโGradio 5.20.1 event listener vibes!
|
| 186 |
demo.load(lambda h: "\n".join(h[-5:]), inputs=[history], outputs=[history_output])
|
| 187 |
|
| 188 |
+
# ๐ Launch the circusโstep right up, folks!
|
| 189 |
demo.launch()
|