gospacedev commited on
Commit
420df50
·
1 Parent(s): 93baf69

format app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -7,7 +7,6 @@ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
7
  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: """
8
 
9
 
10
-
11
  def generate_translation(prompt):
12
  generate_kwargs = dict(
13
  temperature=0.01,
@@ -19,28 +18,23 @@ def generate_translation(prompt):
19
  )
20
 
21
  formatted_prompt = system_instructions + prompt + "[/INST]"
22
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
 
23
  output = ""
24
  emoji_pattern = r"[^\u0021-\u007E\u00A0-\uD7FF\uE000-\uFDCF\uFF00-\uFFEF\u10000-\u10FFFF\u0300-\u036F\u1F00-\u1F1F\u1F20-\u1F7F\u2600-\u26FF\u2700-\u27BF]+?"
25
 
26
- for response in stream:
27
- output += response.token.text
28
- yield output
29
-
30
  filtered_output = re.findall(emoji_pattern, output)
31
 
32
  return ''.join(filtered_output)
33
 
34
 
35
-
36
-
37
-
38
  with gr.Blocks() as demo:
39
  with gr.Row():
40
  name = gr.Textbox(label="Enter text")
41
  output = gr.Textbox(label="Translation")
42
  translate_btn = gr.Button("Translate!")
43
- translate_btn.click(fn=generate_translation, inputs=name, outputs=output, api_name="translate")
 
44
 
45
  if __name__ == "__main__":
46
- demo.launch(show_api=False)
 
7
  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: """
8
 
9
 
 
10
  def generate_translation(prompt):
11
  generate_kwargs = dict(
12
  temperature=0.01,
 
18
  )
19
 
20
  formatted_prompt = system_instructions + prompt + "[/INST]"
21
+ stream = client.text_generation(
22
+ formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
23
  output = ""
24
  emoji_pattern = r"[^\u0021-\u007E\u00A0-\uD7FF\uE000-\uFDCF\uFF00-\uFFEF\u10000-\u10FFFF\u0300-\u036F\u1F00-\u1F1F\u1F20-\u1F7F\u2600-\u26FF\u2700-\u27BF]+?"
25
 
 
 
 
 
26
  filtered_output = re.findall(emoji_pattern, output)
27
 
28
  return ''.join(filtered_output)
29
 
30
 
 
 
 
31
  with gr.Blocks() as demo:
32
  with gr.Row():
33
  name = gr.Textbox(label="Enter text")
34
  output = gr.Textbox(label="Translation")
35
  translate_btn = gr.Button("Translate!")
36
+ translate_btn.click(fn=generate_translation, inputs=name,
37
+ outputs=output, api_name="translate")
38
 
39
  if __name__ == "__main__":
40
+ demo.launch(show_api=False)