haepada commited on
Commit
2ff0e01
·
verified ·
1 Parent(s): 9069bef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -12
app.py CHANGED
@@ -793,19 +793,97 @@ def create_interface():
793
  )
794
  return app
795
 
796
- if __name__ == "__main__":
797
- os.makedirs("static/icons", exist_ok=True)
798
- os.makedirs("assets", exist_ok=True)
799
  demo = create_interface()
800
- demo.launch(
801
- debug=True,
802
- share=True,
803
- server_name="0.0.0.0",
804
- server_port=7860,
805
- show_error=True,
806
- height=None,
807
- width="100%"
808
- # 서버 실행
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
  app.run(
810
  host="0.0.0.0",
811
  port=7860,
 
793
  )
794
  return app
795
 
796
+ # Gradio 인터페이스 생성 함수
797
+ def create_gradio_interface():
 
798
  demo = create_interface()
799
+ return demo
800
+
801
+ # Flask 라우트 추가
802
+ @app.route('/')
803
+ def root():
804
+ return render_template('index.html')
805
+
806
+ @app.route('/manifest.json')
807
+ def manifest():
808
+ return send_from_directory('static', 'manifest.json')
809
+
810
+ @app.route('/service-worker.js')
811
+ def service_worker():
812
+ return send_from_directory('static', 'service-worker.js')
813
+
814
+ @app.route('/static/icons/<path:path>')
815
+ def serve_icons(path):
816
+ return send_from_directory('static/icons', path)
817
+
818
+ @app.route('/assets/<path:path>')
819
+ def serve_custom_assets(path):
820
+ return send_from_directory('assets', path)
821
+
822
+ if __name__ == "__main__":
823
+ # 필요한 디렉토리 생성
824
+ for directory in ['static/icons', 'assets', 'templates']:
825
+ os.makedirs(directory, exist_ok=True)
826
+
827
+ # PWA 파일 존재 확인 및 생성
828
+ if not os.path.exists('templates/index.html'):
829
+ with open('templates/index.html', 'w', encoding='utf-8') as f:
830
+ f.write('''<!DOCTYPE html>
831
+ <html lang="ko">
832
+ <head>
833
+ <meta charset="UTF-8">
834
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
835
+ <title>디지털 굿판</title>
836
+ <link rel="manifest" href="/manifest.json">
837
+ <meta name="theme-color" content="#000000">
838
+ <meta name="apple-mobile-web-app-capable" content="yes">
839
+ <meta name="apple-mobile-web-app-status-bar-style" content="black">
840
+ <meta name="apple-mobile-web-app-title" content="디지털 굿판">
841
+ <link rel="apple-touch-icon" href="/static/icons/icon-152x152.png">
842
+ <script>
843
+ // 화면 꺼짐 방지
844
+ async function preventSleep() {
845
+ try {
846
+ if ('wakeLock' in navigator) {
847
+ const wakeLock = await navigator.wakeLock.request('screen');
848
+ console.log('화면 켜짐 유지 활성화');
849
+
850
+ document.addEventListener('visibilitychange', async () => {
851
+ if (document.visibilityState === 'visible') {
852
+ await preventSleep();
853
+ }
854
+ });
855
+ }
856
+ } catch (err) {
857
+ console.log('화면 켜짐 유지 실패:', err);
858
+ }
859
+ }
860
+
861
+ // 서비스 워커 등록
862
+ if ('serviceWorker' in navigator) {
863
+ window.addEventListener('load', async () => {
864
+ try {
865
+ const registration = await navigator.serviceWorker.register('/service-worker.js');
866
+ console.log('ServiceWorker 등록 성공:', registration.scope);
867
+ await preventSleep();
868
+ } catch (err) {
869
+ console.log('ServiceWorker 등록 실패:', err);
870
+ }
871
+ });
872
+ }
873
+ </script>
874
+ </head>
875
+ <body>
876
+ <div id="gradio-app"></div>
877
+ </body>
878
+ </html>''')
879
+
880
+ # Gradio 앱 생성
881
+ demo = create_gradio_interface()
882
+
883
+ # Flask 앱에 Gradio 마운트
884
+ app = gr.mount_gradio_app(app, demo, path="/gradio")
885
+
886
+ # Flask 서버 실행
887
  app.run(
888
  host="0.0.0.0",
889
  port=7860,