Spaces:
Runtime error
Runtime error
Update
Browse files
app.py
CHANGED
@@ -1,7 +1,169 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
|
5 |
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# def greet(name):
|
4 |
+
# return "Hello " + name + "!!"
|
5 |
|
6 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
# iface.launch()
|
8 |
+
|
9 |
+
import spaces
|
10 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, Trainer, TrainingArguments, pipeline, set_seed
|
11 |
+
|
12 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
13 |
+
|
14 |
+
repo_id = "j2moreno/test-model/saved_model"
|
15 |
+
s
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(repo_id).to(device)
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
18 |
+
# feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
|
19 |
+
|
20 |
+
SEED = 42
|
21 |
+
|
22 |
+
default_text = "Ask me about Leonardo Moreno"
|
23 |
+
# examples = [
|
24 |
+
# [
|
25 |
+
# "Remember - this is only the first iteration of the model! To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data by a factor of five times.",
|
26 |
+
# "A male speaker with a low-pitched voice delivering his words at a fast pace in a small, confined space with a very clear audio and an animated tone."
|
27 |
+
# ],
|
28 |
+
# [
|
29 |
+
# "'This is the best time of my life, Bartley,' she said happily.",
|
30 |
+
# "A female speaker with a slightly low-pitched, quite monotone voice delivers her words at a slightly faster-than-average pace in a confined space with very clear audio.",
|
31 |
+
# ],
|
32 |
+
# [
|
33 |
+
# "Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
|
34 |
+
# "A male speaker with a slightly high-pitched voice delivering his words at a slightly slow pace in a small, confined space with a touch of background noise and a quite monotone tone.",
|
35 |
+
# ],
|
36 |
+
# [
|
37 |
+
# "Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
|
38 |
+
# "A male speaker with a low-pitched voice delivers his words at a fast pace and an animated tone, in a very spacious environment, accompanied by noticeable background noise.",
|
39 |
+
# ],
|
40 |
+
# ]
|
41 |
+
|
42 |
+
# def preprocess(text):
|
43 |
+
# text = number_normalizer(text).strip()
|
44 |
+
# text = text.replace("-", " ")
|
45 |
+
# if text[-1] not in punctuation:
|
46 |
+
# text = f"{text}."s
|
47 |
+
|
48 |
+
# abbreviations_pattern = r'\b[A-Z][A-Z\.]+\b'
|
49 |
+
|
50 |
+
# def separate_abb(chunk):
|
51 |
+
# chunk = chunk.replace(".","")
|
52 |
+
# print(chunk)
|
53 |
+
# return " ".join(chunk)
|
54 |
+
|
55 |
+
# abbreviations = re.findall(abbreviations_pattern, text)
|
56 |
+
# for abv in abbreviations:
|
57 |
+
# if abv in text:
|
58 |
+
# text = text.replace(abv, separate_abb(abv))
|
59 |
+
# return text
|
60 |
+
|
61 |
+
@spaces.GPU
|
62 |
+
def generate_response(text):
|
63 |
+
set_seed(SEED)
|
64 |
+
|
65 |
+
tokenized_prompt = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
66 |
+
# print(tokenized_prompt)
|
67 |
+
|
68 |
+
output_sequences = model.generate(**tokenized_prompt, max_length=1024, num_return_sequences=1)
|
69 |
+
decoded_output = tokenizer.decode(output_sequences[0], skip_special_tokens=True)
|
70 |
+
# print(decoded_output)
|
71 |
+
|
72 |
+
return decoded_output
|
73 |
+
|
74 |
+
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
|
75 |
iface.launch()
|
76 |
+
|
77 |
+
# css = """
|
78 |
+
# #share-btn-container {
|
79 |
+
# display: flex;
|
80 |
+
# padding-left: 0.5rem !important;
|
81 |
+
# padding-right: 0.5rem !important;
|
82 |
+
# background-color: #000000;
|
83 |
+
# justify-content: center;
|
84 |
+
# align-items: center;
|
85 |
+
# border-radius: 9999px !important;
|
86 |
+
# width: 13rem;
|
87 |
+
# margin-top: 10px;
|
88 |
+
# margin-left: auto;
|
89 |
+
# flex: unset !important;
|
90 |
+
# }
|
91 |
+
# #share-btn {
|
92 |
+
# all: initial;
|
93 |
+
# color: #ffffff;
|
94 |
+
# font-weight: 600;
|
95 |
+
# cursor: pointer;
|
96 |
+
# font-family: 'IBM Plex Sans', sans-serif;
|
97 |
+
# margin-left: 0.5rem !important;
|
98 |
+
# padding-top: 0.25rem !important;
|
99 |
+
# padding-bottom: 0.25rem !important;
|
100 |
+
# right:0;
|
101 |
+
# }
|
102 |
+
# #share-btn * {
|
103 |
+
# all: unset !important;
|
104 |
+
# }
|
105 |
+
# #share-btn-container div:nth-child(-n+2){
|
106 |
+
# width: auto !important;
|
107 |
+
# min-height: 0px !important;
|
108 |
+
# }
|
109 |
+
# #share-btn-container .wrap {
|
110 |
+
# display: none !important;
|
111 |
+
# }
|
112 |
+
# """
|
113 |
+
# with gr.Blocks(css=css) as block:
|
114 |
+
# gr.HTML(
|
115 |
+
# """
|
116 |
+
# <div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
117 |
+
# <div
|
118 |
+
# style="
|
119 |
+
# display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;
|
120 |
+
# "
|
121 |
+
# >
|
122 |
+
# <h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
|
123 |
+
# Parler-TTS 🗣️
|
124 |
+
# </h1>
|
125 |
+
# </div>
|
126 |
+
# </div>
|
127 |
+
# """
|
128 |
+
# )
|
129 |
+
# gr.HTML(
|
130 |
+
# f"""
|
131 |
+
# <p><a href="https://github.com/huggingface/parler-tts"> Parler-TTS</a> is a training and inference library for
|
132 |
+
# high-fidelity text-to-speech (TTS) models. The model demonstrated here, <a href="https://huggingface.co/parler-tts/parler_tts_mini_v0.1"> Parler-TTS Mini v0.1</a>,
|
133 |
+
# is the first iteration model trained using 10k hours of narrated audiobooks. It generates high-quality speech
|
134 |
+
# with features that can be controlled using a simple text prompt (e.g. gender, background noise, speaking rate, pitch and reverberation).</p>
|
135 |
+
|
136 |
+
# <p>Tips for ensuring good generation:
|
137 |
+
# <ul>
|
138 |
+
# <li>Include the term "very clear audio" to generate the highest quality audio, and "very noisy audio" for high levels of background noise</li>
|
139 |
+
# <li>Punctuation can be used to control the prosody of the generations, e.g. use commas to add small breaks in speech</li>
|
140 |
+
# <li>The remaining speech features (gender, speaking rate, pitch and reverberation) can be controlled directly through the prompt</li>
|
141 |
+
# </ul>
|
142 |
+
# </p>
|
143 |
+
# """
|
144 |
+
# )
|
145 |
+
# with gr.Row():
|
146 |
+
# with gr.Column():
|
147 |
+
# input_text = gr.Textbox(label="Input Text", lines=2, value=default_text, elem_id="input_text")
|
148 |
+
# description = gr.Textbox(label="Description", lines=2, value="", elem_id="input_description")
|
149 |
+
# run_button = gr.Button("Generate Audio", variant="primary")
|
150 |
+
# with gr.Column():
|
151 |
+
# audio_out = gr.Audio(label="Parler-TTS generation", type="numpy", elem_id="audio_out")
|
152 |
+
|
153 |
+
# inputs = [input_text, description]
|
154 |
+
# outputs = [audio_out]
|
155 |
+
# gr.Examples(examples=examples, fn=gen_tts, inputs=inputs, outputs=outputs, cache_examples=True)
|
156 |
+
# run_button.click(fn=gen_tts, inputs=inputs, outputs=outputs, queue=True)
|
157 |
+
# gr.HTML(
|
158 |
+
# """
|
159 |
+
# <p>To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data to 50k hours of speech.
|
160 |
+
# The v1 release of the model will be trained on this data, as well as inference optimisations, such as flash attention
|
161 |
+
# and torch compile, that will improve the latency by 2-4x. If you want to find out more about how this model was trained and even fine-tune it yourself, check-out the
|
162 |
+
# <a href="https://github.com/huggingface/parler-tts"> Parler-TTS</a> repository on GitHub.</p>
|
163 |
+
|
164 |
+
# <p>The Parler-TTS codebase and its associated checkpoints are licensed under <a href='https://github.com/huggingface/parler-tts?tab=Apache-2.0-1-ov-file#readme'> Apache 2.0</a>.</p>
|
165 |
+
# """
|
166 |
+
# )
|
167 |
+
|
168 |
+
# block.queue()
|
169 |
+
# block.launch(share=True)
|