Hammedalmodel commited on
Commit
bd0d43f
Β·
verified Β·
1 Parent(s): 78570ac

Update app.py

Browse files

Fixed missing words

Files changed (1) hide show
  1. app.py +11 -33
app.py CHANGED
@@ -3,16 +3,19 @@ import tempfile
3
  import json
4
  import pandas as pd
5
  import gradio as gr
 
6
  from aeneas.executetask import ExecuteTask
7
  from aeneas.task import Task
8
  import traceback
9
  import re
10
  import webvtt
11
- import threading
12
  import uvicorn
13
  import subprocess
14
  import shutil
15
  from pathlib import Path
 
 
 
16
 
17
 
18
 
@@ -68,7 +71,7 @@ def segment_text_file(input_content, output_path,):
68
  current_line = current_line[:-(len(moved_word))].rstrip()
69
 
70
  result.append(current_line.strip())
71
- current_line = moved_word + " "
72
  else:
73
  result.append(current_line.strip())
74
  current_line = remaining_line + " " + word + " "
@@ -494,35 +497,6 @@ def create_interface():
494
  return interface
495
 
496
 
497
- def run_fastapi():
498
- uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
499
-
500
-
501
- def main():
502
- try:
503
- threading.Thread(target=run_fastapi, daemon=True).start()
504
-
505
- interface = create_interface()
506
- print("πŸš€ Starting Gradio UI on http://localhost:7860")
507
- print("🧠 FastAPI JSON endpoint available at http://localhost:8000/align")
508
-
509
- interface.launch(
510
- server_name="0.0.0.0",
511
- server_port=7860,
512
- share=False,
513
- debug=False
514
- )
515
-
516
- except ImportError as e:
517
- print("❌ Missing dependency:", e)
518
- except Exception as e:
519
- print("❌ Error launching application:", e)
520
-
521
-
522
- from fastapi import FastAPI, UploadFile, File, Form, HTTPException
523
- from fastapi.responses import JSONResponse
524
- from fastapi.middleware.cors import CORSMiddleware
525
-
526
  fastapi_app = FastAPI()
527
 
528
  fastapi_app.add_middleware(
@@ -533,7 +507,7 @@ fastapi_app.add_middleware(
533
  allow_headers=["*"],
534
  )
535
 
536
- @fastapi_app.post("/align")
537
  async def align_api(
538
  media_file: UploadFile = File(...),
539
  text_file: UploadFile = File(...),
@@ -605,5 +579,9 @@ async def align_api(
605
  )
606
 
607
 
 
 
 
 
608
  if __name__ == "__main__":
609
- main()
 
3
  import json
4
  import pandas as pd
5
  import gradio as gr
6
+ from gradio.routes import mount_gradio_app
7
  from aeneas.executetask import ExecuteTask
8
  from aeneas.task import Task
9
  import traceback
10
  import re
11
  import webvtt
 
12
  import uvicorn
13
  import subprocess
14
  import shutil
15
  from pathlib import Path
16
+ from fastapi import FastAPI, UploadFile, File, Form, HTTPException
17
+ from fastapi.responses import JSONResponse
18
+ from fastapi.middleware.cors import CORSMiddleware
19
 
20
 
21
 
 
71
  current_line = current_line[:-(len(moved_word))].rstrip()
72
 
73
  result.append(current_line.strip())
74
+ current_line = moved_word + " " + word + " "
75
  else:
76
  result.append(current_line.strip())
77
  current_line = remaining_line + " " + word + " "
 
497
  return interface
498
 
499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  fastapi_app = FastAPI()
501
 
502
  fastapi_app.add_middleware(
 
507
  allow_headers=["*"],
508
  )
509
 
510
+ @fastapi_app.post("/align/")
511
  async def align_api(
512
  media_file: UploadFile = File(...),
513
  text_file: UploadFile = File(...),
 
579
  )
580
 
581
 
582
+ interface = create_interface()
583
+
584
+ app = mount_gradio_app(fastapi_app, interface, path="")
585
+
586
  if __name__ == "__main__":
587
+ uvicorn.run(app, host="0.0.0.0", port=7860)