MZhaovo commited on
Commit
02305ec
1 Parent(s): f22d366

Upload folder using huggingface_hub

Browse files
__pycache__/app.cpython-39.pyc ADDED
Binary file (4.77 kB). View file
 
app.py CHANGED
@@ -21,7 +21,7 @@ import gradio as gr
21
  import webbrowser
22
  from config import config
23
  from tools.translate import translate
24
- from tools.webui import reload_javascript
25
 
26
  device = config.webui_config.device
27
  if device == "mps":
@@ -31,6 +31,7 @@ if device == "mps":
31
  def speak_fn(
32
  text: str,
33
  exceed_flag,
 
34
  speaker="TalkFlower_CNzh",
35
  sdp_ratio=0.2, # SDP/DP混合比
36
  noise_scale=0.6, # 感情
@@ -46,9 +47,9 @@ def speak_fn(
46
  print(f"Too Long Text: {text}")
47
  gr.Warning("Too long! No more than 100 characters. 一口气不要超过 100 个字,憋坏我了。")
48
  if exceed_flag:
49
- return gr.update(value="./assets/audios/nomorethan100.wav", autoplay=True), False
50
  else:
51
- return gr.update(value="./assets/audios/overlength.wav", autoplay=True), True
52
  audio_list = []
53
  if len(text) > 42:
54
  print(f"Long Text: {text}")
@@ -103,7 +104,11 @@ def speak_fn(
103
  audio_list.append(silence) # 将静音添加到列表中
104
 
105
  audio_concat = np.concatenate(audio_list)
106
- return (hps.data.sampling_rate, audio_concat), exceed_flag
 
 
 
 
107
 
108
 
109
  def init_fn():
@@ -117,7 +122,8 @@ with open("./css/style.css", "r", encoding="utf-8") as f:
117
 
118
  with gr.Blocks(css=customCSS) as demo:
119
  exceed_flag = gr.State(value=False)
120
- talkingFlowerPic = gr.HTML("""<img src="file=assets/flower-2x.webp" alt="TalkingFlowerPic">""", elem_id="talking_flower_pic")
 
121
  with gr.Tab("Speak", elem_id="tab-speak"):
122
  speak_input = gr.Textbox(lines=1, label="Talking Flower will say:", elem_classes="wonder-card", elem_id="input_text")
123
  speak_button = gr.Button("Speak!", elem_id="speak_button", elem_classes="main-button wonder-card")
@@ -138,14 +144,14 @@ with gr.Blocks(css=customCSS) as demo:
138
  )
139
  speak_input.submit(
140
  speak_fn,
141
- inputs=[speak_input, exceed_flag],
142
- outputs=[audio_output, exceed_flag],
143
- )
144
  speak_button.click(
145
  speak_fn,
146
- inputs=[speak_input, exceed_flag],
147
- outputs=[audio_output, exceed_flag],
148
- )
149
 
150
 
151
  if __name__ == "__main__":
@@ -156,7 +162,5 @@ if __name__ == "__main__":
156
  demo.launch(
157
  allowed_paths=["./assets"],
158
  show_api=False,
159
- # server_name=server_name,
160
- # server_port=server_port,
161
  inbrowser=True,
162
  )
 
21
  import webbrowser
22
  from config import config
23
  from tools.translate import translate
24
+ from tools.webui import reload_javascript, get_character_html
25
 
26
  device = config.webui_config.device
27
  if device == "mps":
 
31
  def speak_fn(
32
  text: str,
33
  exceed_flag,
34
+ bubble_text,
35
  speaker="TalkFlower_CNzh",
36
  sdp_ratio=0.2, # SDP/DP混合比
37
  noise_scale=0.6, # 感情
 
47
  print(f"Too Long Text: {text}")
48
  gr.Warning("Too long! No more than 100 characters. 一口气不要超过 100 个字,憋坏我了。")
49
  if exceed_flag:
50
+ return gr.update(value="./assets/audios/nomorethan100.wav", autoplay=True), False, "不要超过100个字!"
51
  else:
52
+ return gr.update(value="./assets/audios/overlength.wav", autoplay=True), True, "这句太长啦,憋坏我了!"
53
  audio_list = []
54
  if len(text) > 42:
55
  print(f"Long Text: {text}")
 
104
  audio_list.append(silence) # 将静音添加到列表中
105
 
106
  audio_concat = np.concatenate(audio_list)
107
+ return (hps.data.sampling_rate, audio_concat), exceed_flag, text
108
+
109
+
110
+ def update_bubble_fn(text):
111
+ return gr.update(value=get_character_html(text))
112
 
113
 
114
  def init_fn():
 
122
 
123
  with gr.Blocks(css=customCSS) as demo:
124
  exceed_flag = gr.State(value=False)
125
+ bubble_text = gr.State(value="你好呀!")
126
+ character_area = gr.HTML(get_character_html("你好呀!"), elem_id="character_area")
127
  with gr.Tab("Speak", elem_id="tab-speak"):
128
  speak_input = gr.Textbox(lines=1, label="Talking Flower will say:", elem_classes="wonder-card", elem_id="input_text")
129
  speak_button = gr.Button("Speak!", elem_id="speak_button", elem_classes="main-button wonder-card")
 
144
  )
145
  speak_input.submit(
146
  speak_fn,
147
+ inputs=[speak_input, exceed_flag, bubble_text],
148
+ outputs=[audio_output, exceed_flag, bubble_text],
149
+ ).then(update_bubble_fn, inputs=[speak_input], outputs=[character_area], show_progress=False)
150
  speak_button.click(
151
  speak_fn,
152
+ inputs=[speak_input, exceed_flag, bubble_text],
153
+ outputs=[audio_output, exceed_flag, bubble_text],
154
+ ).then(update_bubble_fn, inputs=[speak_input], outputs=[character_area], show_progress=False)
155
 
156
 
157
  if __name__ == "__main__":
 
162
  demo.launch(
163
  allowed_paths=["./assets"],
164
  show_api=False,
 
 
165
  inbrowser=True,
166
  )
css/style.css CHANGED
@@ -63,11 +63,47 @@ gradio-app {
63
  background-position: center center !important;
64
  }
65
 
66
- .gradio-container {
67
- margin-top: 4rem !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  }
69
-
70
- /* TalkingFlower Image */
71
  #talking_flower_pic img {
72
  height: 10rem;
73
  }
@@ -129,16 +165,6 @@ gradio-app {
129
  }
130
 
131
 
132
- /* TalkingFlower Portrait */
133
- #talking_flower_pic {
134
- display: flex;
135
- align-self: center !important;
136
- width: var(--card-width) !important;
137
- object-fit: cover !important;
138
- object-position: center !important;
139
- justify-content: flex-end;
140
- }
141
-
142
  .wonder-card {
143
  --border-radius: 15px;
144
  --border-color: var(--color-accent-black);
 
63
  background-position: center center !important;
64
  }
65
 
66
+ /* Character Row */
67
+ /* #character_row {
68
+ width: var(--card-width) !important;
69
+ align-self: center;
70
+ } */
71
+ #character_area {
72
+ width: var(--card-width) !important;
73
+ align-self: center;
74
+ }
75
+ .character {
76
+ display: flex;
77
+ flex-direction: row;
78
+ flex-wrap: nowrap;
79
+ justify-content: flex-end;
80
+ align-items: flex-start;
81
+ }
82
+ .text-bubble-content {
83
+ --color: #fff;
84
+ background: var(--color) !important;
85
+ border-radius: 1rem;
86
+ padding: 0.5rem 1rem !important;
87
+ box-shadow: #00000078 0.1rem 0.1rem 0.75rem 0px;
88
+ text-align: center;
89
+ }
90
+ .text-bubble-content::after {
91
+ border: 0.75em solid transparent;
92
+ border-top: 1.5em solid #ffffff;
93
+ content: "";
94
+ position: absolute;
95
+ left: calc(100% - 12em);
96
+ top: calc(100% - 9.75em);
97
+ transform: rotate(-45deg);
98
+ }
99
+ #talking_flower_pic {
100
+ display: flex;
101
+ align-self: center !important;
102
+ object-fit: cover !important;
103
+ object-position: center !important;
104
+ justify-content: flex-end;
105
+ height: 10rem;
106
  }
 
 
107
  #talking_flower_pic img {
108
  height: 10rem;
109
  }
 
165
  }
166
 
167
 
 
 
 
 
 
 
 
 
 
 
168
  .wonder-card {
169
  --border-radius: 15px;
170
  --border-color: var(--color-accent-black);
tools/__pycache__/webui.cpython-39.pyc CHANGED
Binary files a/tools/__pycache__/webui.cpython-39.pyc and b/tools/__pycache__/webui.cpython-39.pyc differ
 
tools/webui.py CHANGED
@@ -4,6 +4,16 @@ import os
4
  GradioTemplateResponseOriginal = gr.routes.templates.TemplateResponse
5
  root_path = os.path.dirname(os.path.realpath(__file__))
6
 
 
 
 
 
 
 
 
 
 
 
7
  def webpath(fn):
8
  if fn.startswith(root_path):
9
  web_path = os.path.relpath(fn, root_path).replace('\\', '/')
 
4
  GradioTemplateResponseOriginal = gr.routes.templates.TemplateResponse
5
  root_path = os.path.dirname(os.path.realpath(__file__))
6
 
7
+ def get_character_html(text):
8
+ return f"""\
9
+ <div class="character">
10
+ <span class="text-bubble-content">
11
+ {text}
12
+ </span>
13
+ <img src="file=assets/flower-2x.webp" id="talking_flower_pic" alt="TalkingFlowerPic">
14
+ </div>
15
+ """
16
+
17
  def webpath(fn):
18
  if fn.startswith(root_path):
19
  web_path = os.path.relpath(fn, root_path).replace('\\', '/')