Spaces:
Runtime error
Runtime error
Commit
·
3cdfead
1
Parent(s):
6ee5351
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Copy of falcon-style-transfer [LLM HF Gradio]
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1RvSebeYBKRqrjgnZoWqO9IuWVMqdZRBS
|
8 |
+
|
9 |
+
## Falcon-7b-instruct
|
10 |
+
"""
|
11 |
+
|
12 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
13 |
+
import transformers, torch, gradio as gr
|
14 |
+
|
15 |
+
model = "tiiuae/falcon-7b-instruct"
|
16 |
+
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
18 |
+
pipeline = transformers.pipeline(
|
19 |
+
"text-generation",
|
20 |
+
model=model,
|
21 |
+
tokenizer=tokenizer,
|
22 |
+
torch_dtype=torch.bfloat16,
|
23 |
+
trust_remote_code=True,
|
24 |
+
device_map="auto",
|
25 |
+
)
|
26 |
+
|
27 |
+
prompt = 'Paraphrase the following sentence delimited by curly brackets into'
|
28 |
+
style = ' exaggerated victorian english: '
|
29 |
+
input_text = '{' + 'Almost lunchtime. Time to eat!' + '}'
|
30 |
+
|
31 |
+
text_prompt = prompt + style + input_text
|
32 |
+
|
33 |
+
def llm(input_text, style):
|
34 |
+
prompt = 'Paraphrase and change the style of the following sentence delimited by curly brackets into an exaggerated '
|
35 |
+
style = style + ' accent: '
|
36 |
+
|
37 |
+
text_prompt = prompt + style + '{' + input_text + '}'
|
38 |
+
|
39 |
+
sequences = pipeline(
|
40 |
+
text_prompt,
|
41 |
+
max_length=256,
|
42 |
+
do_sample=True,
|
43 |
+
num_return_sequences=1,
|
44 |
+
eos_token_id=tokenizer.eos_token_id,
|
45 |
+
return_full_text=False
|
46 |
+
)
|
47 |
+
|
48 |
+
output_text = ''
|
49 |
+
for seq in sequences:
|
50 |
+
output_text = output_text + seq['generated_text']
|
51 |
+
|
52 |
+
return output_text
|
53 |
+
|
54 |
+
#for seq in sequences:
|
55 |
+
# print(f"Result: {seq['generated_text']}")
|
56 |
+
|
57 |
+
title = "Change your Speaking Style!"
|
58 |
+
description = """
|
59 |
+
Write something, select an accent, and change the style of your text in seconds!
|
60 |
+
|
61 |
+
Didn't like the response? Just click on submit again!
|
62 |
+
"""
|
63 |
+
|
64 |
+
article = "This demo uses the [Falcon-7b-Instruct Model](https://huggingface.co/tiiuae/falcon-7b-instruct) and is purely for recreational purposes. View the source code on the [github repo.](https://github.com/sarthakc44/LLMs/tree/main/style-transfer)"
|
65 |
+
|
66 |
+
|
67 |
+
textbox = gr.Textbox(label="Type a few sentences below:", placeholder="Almost lunchtime. Time to eat!", lines=3)
|
68 |
+
radio = gr.Radio(["Crazy Pirate", "Formal Victorian", "Hillbilly Southern", "Casual Talkative", "Flowery Poetic",], label="Choose your accent!")
|
69 |
+
|
70 |
+
demo = gr.Interface(
|
71 |
+
fn=llm,
|
72 |
+
inputs=[textbox,
|
73 |
+
radio,],
|
74 |
+
outputs="text",
|
75 |
+
title=title,
|
76 |
+
description=description,
|
77 |
+
article=article,
|
78 |
+
).launch()
|