Spaces:
Runtime error
Runtime error
Delete app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192# api.pyfrom waitress import servefrom flask import Flask, request, send_fileimport osimport tempfileimport shutilimport zipfileimport rarfilefrom werkzeug.utils import secure_filenamefrom pdf2image import convert_from_pathfrom PIL import Imagefrom moviepy.editor import VideoFileClipfrom pydub import AudioSegment app = Flask(__name__)ALLOWED_EXTENSIONS = {'zip', 'rar', 'pdf', 'wav', 'mp4', 'jpg', 'png', 'jpeg'}
def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
# راهاندازی API به عنوان پردازش پسزمینهdef run_api(): # اجرای فایل api.py به صورت subprocess. subprocess.run(['python', 'api.py'])
# Streamlit UIdef streamlit_app(): st.set_page_config(page_title="File Converter", layout="wide")
TEXTS = { "English": { "title": "Universal File Converter", "desc": "Convert files/archives (ZIP/RAR/PDF/WAV/MP4/IMG)", "upload": "Upload File", "error_type": "Unsupported file type!", "success": "Conversion Successful!", "download": "Download" }, "فارسی": { "title": "مبدل جهانی فایل", "desc": "تبدیل فایل/آرشیو (ZIP/RAR/PDF/WAV/MP4/تصویر)", "upload": "آپلود فایل", "error_type": "نوع فایل پشتیبانی نمیشود!", "success": "تبدیل با موفقیت انجام شد!", "download": "دانلود" } }
lang = st.sidebar.selectbox("", ["English", "فارسی"]) t = TEXTS[lang]
st.title(t["title"]) st.markdown(f"**{t['desc']}**")
uploaded = st.file_uploader(t["upload"], type=ALLOWED_EXTENSIONS)
if uploaded: file_extension = uploaded.name.split('.')[-1].lower() if file_extension not in ALLOWED_EXTENSIONS: st.error(t["error_type"]) elif st.button("Convert"): try: with st.spinner("Processing..."): response = requests.post( "http://localhost:5000/convert", # اتصال به پورت 5000 files={"file": uploaded.getvalue()}, timeout=300 )
if response.status_code == 200: # استخراج نام فایل خروجی از header Content-Disposition cd = response.headers.get('Content-Disposition', '') filename = None if 'filename=' in cd: filename = cd.split("filename=")[1].strip().strip('"') else: filename = f"converted_{uploaded.name}" st.success(t["success"]) st.download_button( label=t["download"], data=response.content, file_name=filename, ) else: st.error(f"Error {response.status_code}: {response.text}")
except Exception as e: st.error(f"Connection error: {str(e)}")
if __name__ == '__main__': serve(app, host="0.0.0.0", port=5000)app.pyDeleted-92