import gradio as gr import os import subprocess from io import BytesIO def convert_to_exe(files): """ 여러 파이썬 파일을 하나의 exe 파일로 변환합니다. Parameters: files (list of gr.FileText): 변환할 파이썬 파일 목록 Returns: str: 변환된 exe 파일의 경로 또는 오류 메시지 """ # 파일 목록을 저장할 변수 file_names = [] # 업로드된 파일 반복 for file in files: # 파일 이름 추출 file_name = file.name # 파일 목록에 추가 file_names.append(file_name) try: # 업로드된 파일을 바이트 형태로 저장합니다. with open(file_name, "wb") as f: f.write(file.read()) # 파일 내용을 바이트로 읽어 저장 except Exception as e: print(f"파일 저장 오류: {e}") return "파일 저장 오류" # PyInstaller를 사용하여 여러 파이썬 파일을 하나의 exe 파일로 변환합니다. file_names_str = " ".join(file_names) output_name = "combined_executable" try: # PyInstaller 명령어 실행 subprocess.run(f"pyinstaller --onefile --name {output_name} {file_names_str}", shell=True, check=True) except subprocess.CalledProcessError as e: print(f"PyInstaller 실행 오류: {e}") return "PyInstaller 실행 오류" except Exception as e: print(f"알 수 없는 오류: {e}") return "알 수 없는 오류" # 변환된 exe 파일 경로를 반환합니다. exe_file = f"dist/{output_name}.exe" return exe_file if os.path.exists(exe_file) else "변환에 실패했습니다." interface = gr.Interface( fn=convert_to_exe, # 변환 함수 inputs=gr.Files(file_count="multiple"), # 여러 파이썬 파일 업로드 outputs=gr.File(), # 변환된 exe 파일 다운로드 title="Python to EXE Converter", # 인터페이스 제목 description="여러 파이썬 파일을 하나의 exe 파일로 변환합니다." # 인터페이스 설명 ) if __name__ == "__main__": interface.launch() # 인터페이스 실행