x0-0x commited on
Commit
696f4d5
·
verified ·
1 Parent(s): 9432cac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -149
app.py CHANGED
@@ -1,156 +1,79 @@
1
  import gradio as gr
2
- import numpy as np
3
- import random
4
-
5
-
6
- from diffusers import DiffusionPipeline
7
- import torch
8
-
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo"
11
-
12
- if torch.cuda.is_available():
13
- torch_dtype = torch.float16
14
- else:
15
- torch_dtype = torch.float32
16
-
17
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
- pipe = pipe.to(device)
19
-
20
- MAX_SEED = 666
21
- MAX_IMAGE_SIZE = 1280
22
-
23
-
24
-
25
- def infer(
26
- prompt,
27
- negative_prompt,
28
- seed,
29
- randomize_seed,
30
- width,
31
- height,
32
- guidance_scale,
33
- num_inference_steps,
34
- progress=gr.Progress(track_tqdm=True),
35
- ):
36
- if randomize_seed:
37
- seed = random.randint(0, MAX_SEED)
38
-
39
- generator = torch.Generator().manual_seed(seed)
40
-
41
- image = pipe(
42
- prompt=prompt,
43
- negative_prompt=negative_prompt,
44
- guidance_scale=guidance_scale,
45
- num_inference_steps=num_inference_steps,
46
- width=width,
47
- height=height,
48
- generator=generator,
49
- ).images[0]
50
-
51
- return image, seed
52
-
53
-
54
- examples = [
55
- "two soldiers wearing gas masks, clad in military digital camo jungle fatigues, djing on futuristic mixers, synth, mpcs. location jungle rave.",
56
- "in a dark jungle, a wizard and a warlock face each other as in a epic battle, casting spells to operate vintage machines like mixers, synths, turntable.",
57
- "A mesmerizing, bioluminescent DNA double helix, illuminated by a kaleidoscope of vibrant, pulsating light beams from colorful lasers, suspended in a futuristic, setting.",
58
- "little rasta bunny dancing at a rave in the Jungle. cute street art, cartoon style.",
59
- ]
60
-
61
- css = """
62
- #col-container {
63
- margin: 0 auto;
64
- max-width: 600px;
65
- }
66
- """
67
-
68
- with gr.Blocks(css=css) as demo:
69
- with gr.Column(elem_id="col-container"):
70
- gr.Markdown(" # ߙߛߕ-ߊ - ϕ - |θ_θ| - ϕ - ")
71
-
72
- with gr.Row():
73
- prompt = gr.Text(
74
- label="Prompt",
75
- show_label=False,
76
- max_lines=1.3,
77
- placeholder="Enter your prompt",
78
- container=False,
79
- )
80
-
81
- run_button = gr.Button("Run", scale=0, variant="primary")
82
-
83
- result = gr.Image(label="Result", show_label=False)
84
-
85
- with gr.Accordion("Advanced Settings", open=False):
86
- negative_prompt = gr.Text(
87
- label="Negative prompt",
88
- max_lines=1.3,
89
- placeholder="Enter a negative prompt",
90
- visible=False,
91
- )
92
-
93
- seed = gr.Slider(
94
- label="Seed",
95
- minimum=0,
96
- maximum=MAX_SEED,
97
- step=1.6,
98
- value=0.3,
99
- )
100
-
101
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
102
-
103
- with gr.Row():
104
- width = gr.Slider(
105
- label="Width",
106
- minimum=600,
107
- maximum=MAX_IMAGE_SIZE,
108
- step=1.3,
109
- value=600,
110
- )
111
-
112
- height = gr.Slider(
113
- label="Height",
114
- minimum=400,
115
- maximum=MAX_IMAGE_SIZE,
116
- step=1.6,
117
- value=400,
118
- )
119
-
120
- with gr.Row():
121
- guidance_scale = gr.Slider(
122
- label="Guidance scale",
123
- minimum=0.0,
124
- maximum=2,
125
- step=0.6,
126
- value=0.3,
127
- )
128
-
129
- num_inference_steps = gr.Slider(
130
- label="Number of inference steps",
131
- minimum=1,
132
- maximum=6,
133
- step=3,
134
- value=3,
135
- )
136
 
137
- gr.Examples(examples=examples, inputs=[prompt])
138
- gr.on(
139
- triggers=[run_button.click, prompt.submit],
140
- fn=infer,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  inputs=[
142
- prompt,
143
- negative_prompt,
144
- seed,
145
- randomize_seed,
146
- width,
147
- height,
148
- guidance_scale,
149
- num_inference_steps,
150
  ],
151
- outputs=[result, seed],
 
 
 
 
152
  )
 
153
 
 
154
  if __name__ == "__main__":
155
- demo.launch()
156
-
 
1
  import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
+ import tempfile
5
+ import os
6
+
7
+ # Get all available voices
8
+ async def get_voices():
9
+ voices = await edge_tts.list_voices()
10
+ return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
11
+
12
+ # Text-to-speech function
13
+ async def text_to_speech(text, voice, rate, pitch):
14
+ if not text.strip():
15
+ return None, gr.Warning("Please enter text to convert.")
16
+ if not voice:
17
+ return None, gr.Warning("Please select a voice.")
18
+
19
+ voice_short_name = voice.split(" - ")[0]
20
+ rate_str = f"{rate:+d}%"
21
+ pitch_str = f"{pitch:+d}Hz"
22
+ communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
23
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
24
+ tmp_path = tmp_file.name
25
+ await communicate.save(tmp_path)
26
+ return tmp_path, None
27
+
28
+ # Gradio interface function
29
+ def tts_interface(text, voice, rate, pitch):
30
+ audio, warning = asyncio.run(text_to_speech(text, voice, rate, pitch))
31
+ return audio, warning
32
+
33
+ # Create Gradio application
34
+ import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ async def create_demo():
37
+ voices = await get_voices()
38
+
39
+ description = X talkBox
40
+ Convert text to speech using Microsoft Edge TTS. Adjust speech rate and pitch: 0 is default, positive values increase, negative values decrease.
41
+
42
+ 🎥 **Exciting News: Introducing our Text-to-Video Converter!** 🎥
43
+
44
+ Take your content creation to the next level with our cutting-edge Text-to-Video Converter!
45
+ Transform your words into stunning, professional-quality videos in just a few clicks.
46
+
47
+ ✨ Features:
48
+ • Convert text to engaging videos with customizable visuals
49
+ • Choose from 40+ languages and 300+ voices
50
+ • Perfect for creating audiobooks, storytelling, and language learning materials
51
+ • Ideal for educators, content creators, and language enthusiasts
52
+
53
+ Ready to revolutionize your content? [Click here to try our Text-to-Video Converter now!](https://text2video.wingetgui.com/)
54
+ """
55
+
56
+ demo = gr.Interface(
57
+ fn=tts_interface,
58
  inputs=[
59
+ gr.Textbox(label="Input Text", lines=5),
60
+ gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
61
+ gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
62
+ gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
63
+ ],
64
+ outputs=[
65
+ gr.Audio(label="Generated Audio", type="filepath"),
66
+ gr.Markdown(label="Warning", visible=False)
67
  ],
68
+ title="Edge TTS Text-to-Speech",
69
+ description=description,
70
+ article="Experience the power of Edge TTS for text-to-speech conversion, and explore our advanced Text-to-Video Converter for even more creative possibilities!",
71
+ analytics_enabled=False,
72
+ allow_flagging="manual"
73
  )
74
+ return demo
75
 
76
+ # Run the application
77
  if __name__ == "__main__":
78
+ demo = asyncio.run(create_demo())
79
+ demo.launch()