ArmelRandy commited on
Commit
b198cf7
·
1 Parent(s): 03889a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -36,20 +36,23 @@ def identity(index, split):
36
  return ds["prompt"], ds["completion"]
37
 
38
  def save(index, language, split, prompt, completion):
39
- print("Saving ...")
40
- with open("/home/user/app/output.jsonl", "a") as fout :
41
- fout.write(
42
- json.dumps(
43
- {
44
- "prompt" : prompt,
45
- "completion" : completion,
46
- "language" : language,
47
- "index" : index
48
- }
49
- )+"\n"
50
- )
51
- next_index = min(1+index, len(samples[split])-1)
52
- return next_index, samples[split][next_index]["prompt"], samples[split][next_index]["completion"], "", ""
 
 
 
53
 
54
  with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
55
  gr.HTML("""<h1 align="center">MT💫</h1>""")
 
36
  return ds["prompt"], ds["completion"]
37
 
38
  def save(index, language, split, prompt, completion):
39
+ if len(prompt) != 0 and len(completion) != 0 :
40
+ print("Saving ...")
41
+ with open("/home/user/app/output.jsonl", "a") as fout :
42
+ fout.write(
43
+ json.dumps(
44
+ {
45
+ "prompt" : prompt,
46
+ "completion" : completion,
47
+ "language" : language,
48
+ "index" : index
49
+ }
50
+ )+"\n"
51
+ )
52
+ next_index = min(1+index, len(samples[split])-1)
53
+ return next_index, samples[split][next_index]["prompt"], samples[split][next_index]["completion"], "", ""
54
+ else :
55
+ return index, samples[split][index]["prompt"], samples[split][index]["completion"], "", ""
56
 
57
  with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
58
  gr.HTML("""<h1 align="center">MT💫</h1>""")