versae commited on
Commit
35bb108
1 Parent(s): 6d3ff00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -15,7 +15,14 @@ def modernisa(lines=None, file_obj=None):
15
  outputs = []
16
  for line in lines:
17
  outputs += text2text_generator([line], max_length=150)
18
- return "<br/>".join(output["generated_text"] for output in outputs)
 
 
 
 
 
 
 
19
 
20
 
21
  samples = [
@@ -36,8 +43,11 @@ porque el pensamiento creo"""
36
  gr.Interface(
37
  fn=modernisa,
38
  inputs=[
39
- gr.inputs.Textbox(lines=12, label="Enter Old Spanish", default=random.choice(samples), optional=True),
40
  gr.inputs.File(file_count="single", label="Or upload a plain text file (.txt)", type="file", optional=True),
41
  ],
42
- outputs=gr.outputs.HTML(label="Modern Spanish"),
 
 
 
43
  ).launch(inline=False)
 
15
  outputs = []
16
  for line in lines:
17
  outputs += text2text_generator([line], max_length=150)
18
+ generated_text = "<br/>".join(output["generated_text"] for output in outputs)
19
+ if file_obj:
20
+ output_file = f"{file_obj.name.rsplit('.', 1)[0]}_modernized.txt"
21
+ else:
22
+ output_file = "modernized.txt"
23
+ with open(output_file) as output:
24
+ output.write(generated_text)
25
+ return generated_text, output
26
 
27
 
28
  samples = [
 
43
  gr.Interface(
44
  fn=modernisa,
45
  inputs=[
46
+ gr.inputs.Textbox(lines=12, label="Enter Old Spanish", default=random.choice(samples)),
47
  gr.inputs.File(file_count="single", label="Or upload a plain text file (.txt)", type="file", optional=True),
48
  ],
49
+ outputs=[
50
+ gr.outputs.HTML(label="Modern Spanish"),
51
+ gr.outputs.File(label="Download file")
52
+ ]
53
  ).launch(inline=False)