BlinkDL commited on
Commit
2d1a42e
1 Parent(s): 6d616df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -30
app.py CHANGED
@@ -21,28 +21,22 @@ def generate_prompt(instruction, input=None):
21
  instruction = instruction.strip().replace('\r\n','\n').replace('\n\n','\n')
22
  input = input.strip().replace('\r\n','\n').replace('\n\n','\n')
23
  if input:
24
- return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
25
 
26
- # Instruction:
27
- {instruction}
28
 
29
- # Input:
30
- {input}
31
-
32
- # Response:
33
- """
34
  else:
35
- return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
 
 
36
 
37
- # Instruction:
38
- {instruction}
39
 
40
- # Response:
41
- """
42
 
43
  def evaluate(
44
- instruction,
45
- input=None,
46
  token_count=200,
47
  temperature=1.0,
48
  top_p=0.7,
@@ -54,11 +48,6 @@ def evaluate(
54
  alpha_presence = presencePenalty,
55
  token_ban = [], # ban the generation of some tokens
56
  token_stop = [0]) # stop generation whenever you see any token here
57
-
58
- instruction = instruction.strip().replace('\r\n','\n').replace('\n\n','\n')
59
- input = input.strip().replace('\r\n','\n').replace('\n\n','\n')
60
- ctx = generate_prompt(instruction, input)
61
-
62
  all_tokens = []
63
  out_last = 0
64
  out_str = ''
@@ -95,13 +84,12 @@ def evaluate(
95
  yield out_str.strip()
96
 
97
  examples = [
98
- ["Tell me about ravens.", "", 300, 1, 0.5, 0.4, 0.4],
99
- ["Write a python function to mine 1 BTC, with details and comments.", "", 300, 1, 0.5, 0.4, 0.4],
100
- ["Write a song about ravens.", "", 300, 1, 0.5, 0.4, 0.4],
101
- ["Explain the following metaphor: Life is like cats.", "", 300, 1, 0.5, 0.4, 0.4],
102
- ["Write a story using the following information", "A man named Alex chops a tree down", 300, 1, 0.5, 0.4, 0.4],
103
- ["Generate a list of adjectives that describe a person as brave.", "", 300, 1, 0.5, 0.4, 0.4],
104
- ["You have $100, and your goal is to turn that into as much money as possible with AI and Machine Learning. Please respond with detailed plan.", "", 300, 1, 0.5, 0.4, 0.4],
105
  ]
106
 
107
  ##########################################################################
@@ -124,10 +112,10 @@ with gr.Blocks(title=title) as demo:
124
  submit = gr.Button("Submit", variant="primary")
125
  clear = gr.Button("Clear", variant="secondary")
126
  output = gr.Textbox(label="Output", lines=5)
127
- data = gr.Dataset(components=[instruction, input, token_count, temperature, top_p, presence_penalty, count_penalty], samples=examples, label="Example Instructions", headers=["Instruction", "Input", "Max Tokens", "Temperature", "Top P", "Presence Penalty", "Count Penalty"])
128
- submit.click(evaluate, [instruction, input, token_count, temperature, top_p, presence_penalty, count_penalty], [output])
129
  clear.click(lambda: None, [], [output])
130
- data.click(lambda x: x, [data], [instruction, input, token_count, temperature, top_p, presence_penalty, count_penalty])
131
 
132
  demo.queue(concurrency_count=1, max_size=10)
133
  demo.launch(share=False)
 
21
  instruction = instruction.strip().replace('\r\n','\n').replace('\n\n','\n')
22
  input = input.strip().replace('\r\n','\n').replace('\n\n','\n')
23
  if input:
24
+ return f"""Instruction: {instruction}
25
 
26
+ Input: {input}
 
27
 
28
+ Response:"""
 
 
 
 
29
  else:
30
+ return f"""User: hi
31
+
32
+ Assistant: Hi. I am your assistant and I will provide expert full response in full details. Please feel free to ask any question and I will always answer it.
33
 
34
+ User: {instruction}
 
35
 
36
+ Assistant:"""
 
37
 
38
  def evaluate(
39
+ ctx,
 
40
  token_count=200,
41
  temperature=1.0,
42
  top_p=0.7,
 
48
  alpha_presence = presencePenalty,
49
  token_ban = [], # ban the generation of some tokens
50
  token_stop = [0]) # stop generation whenever you see any token here
 
 
 
 
 
51
  all_tokens = []
52
  out_last = 0
53
  out_str = ''
 
84
  yield out_str.strip()
85
 
86
  examples = [
87
+ [generate_prompt("Tell me about ravens."), 500, 1, 0.5, 0.4, 0.4],
88
+ [generate_prompt("Write a python function to mine 1 BTC."), 500, 1, 0.5, 0.4, 0.4],
89
+ [generate_prompt("Write a song about ravens.", "", 500, 1, 0.5, 0.4, 0.4],
90
+ [generate_prompt("Write a story using the following information", "A man named Alex chops a tree down", 500, 1, 0.5, 0.4, 0.4],
91
+ [generate_prompt("Generate a list of adjectives that describe a person as brave."), 500, 1, 0.5, 0.4, 0.4],
92
+ [generate_prompt("You have $100, and your goal is to turn that into as much money as possible with AI and Machine Learning. Please respond with detailed plan."), 500, 1, 0.5, 0.4, 0.4],
 
93
  ]
94
 
95
  ##########################################################################
 
112
  submit = gr.Button("Submit", variant="primary")
113
  clear = gr.Button("Clear", variant="secondary")
114
  output = gr.Textbox(label="Output", lines=5)
115
+ data = gr.Dataset(components=[prompt, token_count, temperature, top_p, presence_penalty, count_penalty], samples=examples, label="Example Instructions", headers=["Prompt", "Max Tokens", "Temperature", "Top P", "Presence Penalty", "Count Penalty"])
116
+ submit.click(evaluate, [prompt, token_count, temperature, top_p, presence_penalty, count_penalty], [output])
117
  clear.click(lambda: None, [], [output])
118
+ data.click(lambda x: x, [data], [prompt, token_count, temperature, top_p, presence_penalty, count_penalty])
119
 
120
  demo.queue(concurrency_count=1, max_size=10)
121
  demo.launch(share=False)