Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,7 @@ def get_target_style_embeddings(target_texts_batch):
|
|
25 |
|
26 |
def run_tinystyler_batch(source_texts, target_example_texts_batch, reranking, temperature, top_p):
|
27 |
inputs = tokenizer(source_texts, return_tensors="pt")
|
|
|
28 |
|
29 |
# Generate the output with specified temperature and top_p
|
30 |
output = model.generate(
|
@@ -38,14 +39,15 @@ def run_tinystyler_batch(source_texts, target_example_texts_batch, reranking, te
|
|
38 |
generated_texts = tokenizer.decode_batch(output, skip_special_tokens=True)
|
39 |
return generated_texts
|
40 |
|
41 |
-
def run_tinystyler(source_text,
|
42 |
-
|
|
|
43 |
|
44 |
# Preset examples with cached generations
|
45 |
preset_examples = {
|
46 |
"Example 1": {
|
47 |
"source_text": "Once upon a time in a small village",
|
48 |
-
"
|
49 |
"reranking": 5,
|
50 |
"temperature": 1.0,
|
51 |
"top_p": 1.0,
|
@@ -53,7 +55,7 @@ preset_examples = {
|
|
53 |
},
|
54 |
"Example 2": {
|
55 |
"source_text": "The quick brown fox",
|
56 |
-
"
|
57 |
"reranking": 5,
|
58 |
"temperature": 0.9,
|
59 |
"top_p": 0.9,
|
@@ -70,7 +72,7 @@ with gr.Blocks(theme="ParityError/[email protected]") as demo:
|
|
70 |
example_dropdown = gr.Dropdown(label="Examples", choices=list(preset_examples.keys()))
|
71 |
|
72 |
source_text = gr.Textbox(lines=3, placeholder="Enter the source text to transform into the target style...", label="Source Text")
|
73 |
-
|
74 |
reranking = gr.Slider(1, 10, value=5, step=1, label="Re-ranking")
|
75 |
temperature = gr.Slider(0.1, 2.0, value=1.0, step=0.1, label="Temperature")
|
76 |
top_p = gr.Slider(0.0, 1.0, value=1.0, step=0.1, label="Top-P")
|
@@ -88,9 +90,9 @@ with gr.Blocks(theme="ParityError/[email protected]") as demo:
|
|
88 |
)
|
89 |
|
90 |
btn = gr.Button("Generate")
|
91 |
-
btn.click(run_tinystyler, [source_text,
|
92 |
|
93 |
# Initialize the fields with the first example
|
94 |
-
example_dropdown.value, (source_text.value,
|
95 |
|
96 |
demo.launch()
|
|
|
25 |
|
26 |
def run_tinystyler_batch(source_texts, target_example_texts_batch, reranking, temperature, top_p):
|
27 |
inputs = tokenizer(source_texts, return_tensors="pt")
|
28 |
+
target_style_embeddings = get_target_style_embeddings(target_texts_batch)
|
29 |
|
30 |
# Generate the output with specified temperature and top_p
|
31 |
output = model.generate(
|
|
|
39 |
generated_texts = tokenizer.decode_batch(output, skip_special_tokens=True)
|
40 |
return generated_texts
|
41 |
|
42 |
+
def run_tinystyler(source_text, target_texts, reranking, temperature, top_p):
|
43 |
+
target_texts = [target_text.strip() for target_text in target_texts.split("\n")]
|
44 |
+
return run_tinystyler_batch([source_text], [target_texts], reranking, temperature, top_p)[0]
|
45 |
|
46 |
# Preset examples with cached generations
|
47 |
preset_examples = {
|
48 |
"Example 1": {
|
49 |
"source_text": "Once upon a time in a small village",
|
50 |
+
"target_texts": "In a land far away, there was a kingdom ruled by a wise king. Every day, the people of the kingdom would gather to listen to the king's stories, which were full of wisdom and kindness.",
|
51 |
"reranking": 5,
|
52 |
"temperature": 1.0,
|
53 |
"top_p": 1.0,
|
|
|
55 |
},
|
56 |
"Example 2": {
|
57 |
"source_text": "The quick brown fox",
|
58 |
+
"target_texts": "A nimble, chocolate-colored fox swiftly darted through the emerald forest, weaving between trees with grace and agility.",
|
59 |
"reranking": 5,
|
60 |
"temperature": 0.9,
|
61 |
"top_p": 0.9,
|
|
|
72 |
example_dropdown = gr.Dropdown(label="Examples", choices=list(preset_examples.keys()))
|
73 |
|
74 |
source_text = gr.Textbox(lines=3, placeholder="Enter the source text to transform into the target style...", label="Source Text")
|
75 |
+
target_texts = gr.Textbox(lines=5, placeholder="Enter example texts of the target style (one per line)...", label="Example Texts of the Target Style")
|
76 |
reranking = gr.Slider(1, 10, value=5, step=1, label="Re-ranking")
|
77 |
temperature = gr.Slider(0.1, 2.0, value=1.0, step=0.1, label="Temperature")
|
78 |
top_p = gr.Slider(0.0, 1.0, value=1.0, step=0.1, label="Top-P")
|
|
|
90 |
)
|
91 |
|
92 |
btn = gr.Button("Generate")
|
93 |
+
btn.click(run_tinystyler, [source_text, target_texts, reranking, temperature, top_p], output)
|
94 |
|
95 |
# Initialize the fields with the first example
|
96 |
+
example_dropdown.value, (source_text.value, target_texts.value, reranking.value, temperature.value, top_p.value, output.value) = list(preset_examples.keys())[0], set_example(list(preset_examples.keys())[0])
|
97 |
|
98 |
demo.launch()
|