Brunwo commited on
Commit
b5eef9f
1 Parent(s): 30933b5

add build step into the launch (for HF space deploy)

Browse files
Files changed (1) hide show
  1. app.py +14 -45
app.py CHANGED
@@ -51,7 +51,7 @@ def setup_translation(lang_code):
51
  translation.install()
52
  return translation.gettext # Return the translation function '_'
53
  except FileNotFoundError:
54
- logger.error(f"Translation file for language '{lang_code}' not found.")
55
  return lambda s: s # Fallback to no translation
56
  except UnicodeDecodeError as e:
57
  logger.error(f"UnicodeDecodeError: {e}")
@@ -648,54 +648,23 @@ with gr.Blocks(theme='lone17/kotaemon', title="Text to Audio") as demo:
648
  demo.queue(max_size=20, default_concurrency_limit=32)
649
 
650
 
 
 
 
 
 
 
 
 
 
 
651
 
652
 
653
  # Launch the Gradio app
654
  if __name__ == "__main__":
655
 
 
 
 
656
  load_dotenv() # This line brings all environment variables from .env into os.environ
657
  app, local_url, share_url = demo.launch(share=False)
658
-
659
- # app.app_context()
660
- # CORS(app.servers) # This line enables CORS for all routes
661
-
662
- # # Create a FastAPI app
663
- # app = FastAPI()
664
-
665
- # # Define an API endpoint for generating audio
666
- # @app.post("/api/generate-audio")
667
- # async def api_generate_audio(data: dict):
668
- # try:
669
- # audio_file, transcript, original_text, error = validate_and_generate_audio(
670
- # data.get("url"),
671
- # data.get("openai_api_key"),
672
- # data.get("text_model"),
673
- # data.get("audio_model"),
674
- # data.get("speaker_1_voice"),
675
- # data.get("speaker_2_voice"),
676
- # data.get("api_base"),
677
- # data.get("intro_instructions"),
678
- # data.get("text_instructions"),
679
- # data.get("scratch_pad_instructions"),
680
- # data.get("prelude_dialog"),
681
- # data.get("podcast_dialog_instructions"),
682
- # data.get("edited_transcript"),
683
- # data.get("user_feedback"),
684
- # )
685
- # if error:
686
- # return {"error": error}
687
- # return {"audio_file": audio_file, "transcript": transcript}
688
- # except Exception as e:
689
- # return {"error": str(e)}
690
-
691
- # # Mount the Gradio app
692
- # gradio_app, _, _ = demo.launch(prevent_thread_lock=True)
693
- # app = gr.mount_gradio_app(app, gradio_app, path="/")
694
-
695
- # # Launch the FastAPI app
696
- # if __name__ == "__main__":
697
- # import uvicorn
698
- # load_dotenv()
699
- # uvicorn.run(app, host="0.0.0.0", port=7860)
700
- # load_dotenv()
701
- # uvicorn.run(app, host="0.0.0.0", port=7860)
 
51
  translation.install()
52
  return translation.gettext # Return the translation function '_'
53
  except FileNotFoundError:
54
+ logger.error(f"Translation file for language '{lang_code}' not found in {locale_path}")
55
  return lambda s: s # Fallback to no translation
56
  except UnicodeDecodeError as e:
57
  logger.error(f"UnicodeDecodeError: {e}")
 
648
  demo.queue(max_size=20, default_concurrency_limit=32)
649
 
650
 
651
+ import subprocess
652
+
653
+ def execute_command(cmd):
654
+ try:
655
+ # Use subprocess to run the command
656
+ result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
657
+ # Return the stdout and stderr from the command execution
658
+ return result.stdout + result.stderr
659
+ except Exception as e:
660
+ return str(e)
661
 
662
 
663
  # Launch the Gradio app
664
  if __name__ == "__main__":
665
 
666
+ logger.info(execute_command('msgfmt locales/fr/LC_MESSAGES/messages.po -o locales/fr/LC_MESSAGES/messages.mo'))
667
+ logger.info(execute_command('msgfmt locales/en/LC_MESSAGES/messages.po -o locales/en/LC_MESSAGES/messages.mo'))
668
+
669
  load_dotenv() # This line brings all environment variables from .env into os.environ
670
  app, local_url, share_url = demo.launch(share=False)