attendantelectro commited on
Commit
7e228e5
·
verified ·
1 Parent(s): 97ab97f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -92
app.py DELETED
@@ -1,92 +0,0 @@
1
- # api.py
2
- from waitress import serve
3
- from flask import Flask, request, send_file
4
- import os
5
- import tempfile
6
- import shutil
7
- import zipfile
8
- import rarfile
9
- from werkzeug.utils import secure_filename
10
- from pdf2image import convert_from_path
11
- from PIL import Image
12
- from moviepy.editor import VideoFileClip
13
- from pydub import AudioSegment
14
-
15
- app = Flask(__name__)
16
- ALLOWED_EXTENSIONS = {'zip', 'rar', 'pdf', 'wav', 'mp4', 'jpg', 'png', 'jpeg'}
17
-
18
- def allowed_file(filename):
19
- return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
20
-
21
- # راه‌اندازی API به عنوان پردازش پس‌زمینه
22
- def run_api():
23
- # اجرای فایل api.py به صورت subprocess.
24
- subprocess.run(['python', 'api.py'])
25
-
26
- # Streamlit UI
27
- def streamlit_app():
28
- st.set_page_config(page_title="File Converter", layout="wide")
29
-
30
- TEXTS = {
31
- "English": {
32
- "title": "Universal File Converter",
33
- "desc": "Convert files/archives (ZIP/RAR/PDF/WAV/MP4/IMG)",
34
- "upload": "Upload File",
35
- "error_type": "Unsupported file type!",
36
- "success": "Conversion Successful!",
37
- "download": "Download"
38
- },
39
- "فارسی": {
40
- "title": "مبدل جهانی فایل",
41
- "desc": "تبدیل فایل/آرشیو (ZIP/RAR/PDF/WAV/MP4/تصویر)",
42
- "upload": "آپلود فایل",
43
- "error_type": "نوع فایل پشتیبانی نمیشود!",
44
- "success": "تبدیل با موفقیت انجام شد!",
45
- "download": "دانلود"
46
- }
47
- }
48
-
49
- lang = st.sidebar.selectbox("", ["English", "فارسی"])
50
- t = TEXTS[lang]
51
-
52
- st.title(t["title"])
53
- st.markdown(f"**{t['desc']}**")
54
-
55
- uploaded = st.file_uploader(t["upload"], type=ALLOWED_EXTENSIONS)
56
-
57
- if uploaded:
58
- file_extension = uploaded.name.split('.')[-1].lower()
59
- if file_extension not in ALLOWED_EXTENSIONS:
60
- st.error(t["error_type"])
61
- elif st.button("Convert"):
62
- try:
63
- with st.spinner("Processing..."):
64
- response = requests.post(
65
- "http://localhost:5000/convert", # اتصال به پورت 5000
66
- files={"file": uploaded.getvalue()},
67
- timeout=300
68
- )
69
-
70
- if response.status_code == 200:
71
- # استخراج نام فایل خروجی از header Content-Disposition
72
- cd = response.headers.get('Content-Disposition', '')
73
- filename = None
74
- if 'filename=' in cd:
75
- filename = cd.split("filename=")[1].strip().strip('"')
76
- else:
77
- filename = f"converted_{uploaded.name}"
78
-
79
- st.success(t["success"])
80
- st.download_button(
81
- label=t["download"],
82
- data=response.content,
83
- file_name=filename,
84
- )
85
- else:
86
- st.error(f"Error {response.status_code}: {response.text}")
87
-
88
- except Exception as e:
89
- st.error(f"Connection error: {str(e)}")
90
-
91
- if __name__ == '__main__':
92
- serve(app, host="0.0.0.0", port=5000)