Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 1782231

Browse files
[feat] add file upload tutorial with basic file analysis functionality
1 parent 5519280 commit 1782231

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

5_file_upload_in_gradio/app.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
app.py
3+
4+
This script creates a simple Gradio application that allows users to upload a file and receive some basic analysis about it, such as the file name and size.
5+
It uses the Gradio library to create a user interface for file uploads and displays the results of the analysis.
6+
"""
7+
8+
import gradio as gr
9+
10+
# Function to analyze the uploaded file
11+
def analyze_file(file):
12+
"""
13+
Analyze the uploaded file and return some information about it.
14+
15+
Args:
16+
file: The uploaded file object.
17+
18+
Returns:
19+
str: A string containing the file name and size.
20+
"""
21+
if file is None:
22+
return "No file uploaded."
23+
24+
# Here you can add your file analysis logic
25+
# For demonstration, we will just return the file name and size
26+
file_name = file.name
27+
28+
return f"File Name: {file_name}"
29+
30+
# Create a Gradio interface for file upload and analysis
31+
interface = gr.Interface(
32+
fn=analyze_file,
33+
inputs=gr.File(label="Upload File"),
34+
outputs=gr.Textbox(label="Analysis Result")
35+
)
36+
37+
if __name__ == "__main__":
38+
# Launch the Gradio interface
39+
interface.launch()

0 commit comments

Comments
 (0)