wasmdashai commited on
Commit
616ff4e
·
verified ·
1 Parent(s): a2515ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -24
app.py CHANGED
@@ -1,31 +1,19 @@
1
- import os
2
  import gradio as gr
3
 
4
- # Define the folder where uploaded files will be saved
5
- upload_folder = "/tmp/uploaded_files"
6
-
7
-
8
- # Ensure the folder exists; if not, create it
9
- if not os.path.exists(upload_folder):
10
- os.makedirs(upload_folder)
11
-
12
- # Function to handle the file upload
13
- def save_file(file):
14
- # Get the file name
15
- file_name = file.name
16
 
17
- # Save the file to the specified folder
18
- file_path = os.path.join(upload_folder, file_name)
19
-
 
20
 
21
- return f"File saved to: {file_path}"
 
22
 
23
- # Create the Gradio interface
24
- iface = gr.Interface(
25
- fn=save_file, # The function to handle file saving
26
- inputs=gr.File(), # Input widget to upload a file
27
- outputs="text" # Output: confirmation message with file path
28
- )
29
 
30
- # Launch the app
31
  iface.launch()
 
 
1
  import gradio as gr
2
 
3
+ def create_and_download_file():
4
+ # تحديد مسار الملف
5
+ file_path = "/tmp/my_file.txt"
 
 
 
 
 
 
 
 
 
6
 
7
+ # كتابة المحتوى إلى الملف
8
+ with open(file_path, "w") as file:
9
+ file.write("This is a file created in Gradio.\n")
10
+ file.write("You can download it after creation.\n")
11
 
12
+ # إرجاع مسار الملف لتنزيله
13
+ return file_path
14
 
15
+ # إنشاء واجهة Gradio للسماح بتنزيل الملف
16
+ iface = gr.Interface(fn=create_and_download_file, inputs=[], outputs=gr.File(label="Download File"))
 
 
 
 
17
 
18
+ # تشغيل التطبيق
19
  iface.launch()