mrfakename commited on
Commit
24f465e
·
verified ·
1 Parent(s): cf1d30e

Sync from GitHub repo

Browse files

This Space is synced from the GitHub repo: https://github.com/SWivid/F5-TTS. Please submit contributions to the Space there

Files changed (2) hide show
  1. app.py +40 -26
  2. pyproject.toml +1 -1
app.py CHANGED
@@ -1,6 +1,7 @@
1
  # ruff: noqa: E402
2
  # Above allows ruff to ignore E402: module level import not at top of file
3
 
 
4
  import json
5
  import re
6
  import tempfile
@@ -11,6 +12,7 @@ import click
11
  import gradio as gr
12
  import numpy as np
13
  import soundfile as sf
 
14
  import torchaudio
15
  from cached_path import cached_path
16
  from transformers import AutoModelForCausalLM, AutoTokenizer
@@ -550,35 +552,47 @@ Have a conversation with an AI using your reference voice!
550
  """
551
  )
552
 
553
- if not USING_SPACES:
554
- load_chat_model_btn = gr.Button("Load Chat Model", variant="primary")
555
-
556
- chat_interface_container = gr.Column(visible=False)
557
 
558
- @gpu_decorator
559
- def load_chat_model():
560
- global chat_model_state, chat_tokenizer_state
561
- if chat_model_state is None:
562
- show_info = gr.Info
563
- show_info("Loading chat model...")
564
- model_name = "Qwen/Qwen2.5-3B-Instruct"
565
- chat_model_state = AutoModelForCausalLM.from_pretrained(
566
- model_name, torch_dtype="auto", device_map="auto"
567
- )
568
- chat_tokenizer_state = AutoTokenizer.from_pretrained(model_name)
569
- show_info("Chat model loaded.")
570
-
571
- return gr.update(visible=False), gr.update(visible=True)
572
-
573
- load_chat_model_btn.click(load_chat_model, outputs=[load_chat_model_btn, chat_interface_container])
574
 
575
- else:
576
- chat_interface_container = gr.Column()
 
 
 
 
 
 
 
 
 
 
577
 
578
- if chat_model_state is None:
579
- model_name = "Qwen/Qwen2.5-3B-Instruct"
580
- chat_model_state = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
581
- chat_tokenizer_state = AutoTokenizer.from_pretrained(model_name)
 
 
 
 
 
582
 
583
  with chat_interface_container:
584
  with gr.Row():
 
1
  # ruff: noqa: E402
2
  # Above allows ruff to ignore E402: module level import not at top of file
3
 
4
+ import gc
5
  import json
6
  import re
7
  import tempfile
 
12
  import gradio as gr
13
  import numpy as np
14
  import soundfile as sf
15
+ import torch
16
  import torchaudio
17
  from cached_path import cached_path
18
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
552
  """
553
  )
554
 
555
+ chat_model_name_list = ["Qwen/Qwen2.5-3B-Instruct",]
 
 
 
556
 
557
+ @gpu_decorator
558
+ def load_chat_model(chat_model_name):
559
+ show_info = gr.Info
560
+ global chat_model_state, chat_tokenizer_state
561
+ if chat_model_state is not None:
562
+ chat_model_state = None
563
+ chat_tokenizer_state = None
564
+ gc.collect()
565
+ torch.cuda.empty_cache()
566
+
567
+ show_info(f"Loading chat model: {chat_model_name}")
568
+ chat_model_state = AutoModelForCausalLM.from_pretrained(chat_model_name, torch_dtype="auto", device_map="auto")
569
+ chat_tokenizer_state = AutoTokenizer.from_pretrained(chat_model_name)
570
+ show_info(f"Chat model {chat_model_name} loaded successfully!")
571
+
572
+ return gr.update(visible=False), gr.update(visible=True)
573
 
574
+ if USING_SPACES:
575
+ load_chat_model(chat_model_name_list[0])
576
+
577
+ chat_model_name_input = gr.Dropdown(
578
+ choices=chat_model_name_list,
579
+ value=chat_model_name_list[0],
580
+ label="Chat Model Name",
581
+ info="Enter the name of a HuggingFace chat model",
582
+ allow_custom_value=not USING_SPACES,
583
+ )
584
+ load_chat_model_btn = gr.Button("Load Chat Model", variant="primary", visible=not USING_SPACES)
585
+ chat_interface_container = gr.Column(visible=USING_SPACES)
586
 
587
+ chat_model_name_input.change(
588
+ lambda: gr.update(visible=True),
589
+ None,
590
+ load_chat_model_btn,
591
+ show_progress="hidden",
592
+ )
593
+ load_chat_model_btn.click(
594
+ load_chat_model, inputs=[chat_model_name_input], outputs=[load_chat_model_btn, chat_interface_container]
595
+ )
596
 
597
  with chat_interface_container:
598
  with gr.Row():
pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
 
5
  [project]
6
  name = "f5-tts"
7
- version = "1.0.8"
8
  description = "F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching"
9
  readme = "README.md"
10
  license = {text = "MIT License"}
 
4
 
5
  [project]
6
  name = "f5-tts"
7
+ version = "1.0.9"
8
  description = "F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching"
9
  readme = "README.md"
10
  license = {text = "MIT License"}