Spaces:
Running
Running
Commit
Β·
8f74626
1
Parent(s):
f478232
added emoji to text features
Browse files
app.py
CHANGED
@@ -32,18 +32,58 @@ def generate_translation(prompt):
|
|
32 |
return ''.join(filtered_output).replace(" ", "").replace("\n", "")
|
33 |
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
with gr.Blocks() as demo:
|
36 |
gr.HTML("""
|
37 |
-
<center><h1>Emoji Translator
|
38 |
-
Translate any text into emojis
|
39 |
</center>
|
|
|
|
|
|
|
|
|
40 |
""")
|
41 |
with gr.Row():
|
42 |
-
|
43 |
output = gr.Textbox(label="Translation")
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
demo.launch(show_api=False)
|
|
|
32 |
return ''.join(filtered_output).replace(" ", "").replace("\n", "")
|
33 |
|
34 |
|
35 |
+
system_instructions = """<s> [INST] You will be provided with emojis, and your task is to translate it into text. DO NOT USE ANY REGULAR EMOJIS. Do your best with text only. Translate this emojis: """
|
36 |
+
|
37 |
+
|
38 |
+
def generate_emoji_translation(prompt):
|
39 |
+
generate_kwargs = dict(
|
40 |
+
temperature=0.01,
|
41 |
+
max_new_tokens=1024,
|
42 |
+
top_p=0.95,
|
43 |
+
repetition_penalty=1.0,
|
44 |
+
do_sample=True,
|
45 |
+
seed=42,
|
46 |
+
)
|
47 |
+
|
48 |
+
formatted_prompt = system_instructions + prompt + "[/INST]"
|
49 |
+
stream = client.text_generation(
|
50 |
+
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
51 |
+
output = ""
|
52 |
+
|
53 |
+
for response in stream:
|
54 |
+
output += response.token.text
|
55 |
+
yield output
|
56 |
+
|
57 |
+
return output
|
58 |
+
|
59 |
with gr.Blocks() as demo:
|
60 |
gr.HTML("""
|
61 |
+
<center><h1>Emoji Translator π€π»</h1>
|
62 |
+
<h3>Translate any text into emojis, and vice versa!</h3>
|
63 |
</center>
|
64 |
+
""")
|
65 |
+
|
66 |
+
gr.Markdown("""
|
67 |
+
# Text to Emoji πβ‘οΈπ»
|
68 |
""")
|
69 |
with gr.Row():
|
70 |
+
text_uesr_input = gr.Textbox(label="Enter text π")
|
71 |
output = gr.Textbox(label="Translation")
|
72 |
+
with gr.Row():
|
73 |
+
translate_btn = gr.Button("Translate π")
|
74 |
+
translate_btn.click(fn=generate_translation, inputs=text_uesr_input,
|
75 |
+
outputs=output, api_name="translate_text")
|
76 |
+
|
77 |
+
gr.Markdown("""
|
78 |
+
# Emoji to Text π»β‘οΈπ
|
79 |
+
""")
|
80 |
+
with gr.Row():
|
81 |
+
emoji_user_input = gr.Textbox(label="Enter emojis π€")
|
82 |
+
output = gr.Textbox(label="Translation")
|
83 |
+
with gr.Row():
|
84 |
+
translate_btn = gr.Button("Translate π")
|
85 |
+
translate_btn.click(fn=generate_emoji_translation, inputs=emoji_user_input,
|
86 |
+
outputs=output, api_name="translate_emojis")
|
87 |
|
88 |
if __name__ == "__main__":
|
89 |
demo.launch(show_api=False)
|