gospacedev commited on
Commit
119f851
1 Parent(s): 0081d5a

update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
+
6
+ system_instructions = """<s> [INST] You will be provided with text, and your task is to translate it into emojis. Do not use any regular text. Do your best with emojis only. Translate this text: """
7
+
8
+
9
+
10
+ def generate_translation(prompt):
11
+ generate_kwargs = dict(
12
+ temperature=0,
13
+ max_new_tokens=1024,
14
+ top_p=0.95,
15
+ repetition_penalty=1.0,
16
+ do_sample=True,
17
+ seed=42,
18
+ )
19
+
20
+ formatted_prompt = system_instructions + prompt + "[/INST]"
21
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
22
+ output = ""
23
+
24
+ for response in stream:
25
+ output += response.token.text
26
+ yield output
27
+ return output
28
+
29
+
30
+
31
+ with gr.Blocks() as demo:
32
+ name = gr.Textbox(label="Enter text")
33
+ output = gr.Textbox(label="Translation")
34
+ translate_btn = gr.Button("Translate!")
35
+ translate_btn.click(fn=generate_translation, inputs=name, outputs=output, api_name="translate")
36
+
37
+ if __name__ == "__main__":
38
+ demo.launch()