Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,19 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
|
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 |
-
#
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
|
|
|
22 |
|
23 |
-
#
|
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 |
-
#
|
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()
|