Matthew Hollings commited on
Commit
ec6ed9c
·
1 Parent(s): 30973d8

Display of the built poem.

Browse files
Files changed (1) hide show
  1. app.py +16 -27
app.py CHANGED
@@ -25,48 +25,37 @@ def twolists(list1, list2):
25
  return newlist
26
 
27
 
28
- # This function structures the space already, set boundarys to the possible.
29
  def build_poem(source_lines, generated_lines):
 
30
  # return a list with the two lists interspersed
31
- print("____build_poem")
32
- print("____source_lines")
33
- print(source_lines)
34
- print("____generated_lines")
35
- print(generated_lines)
36
-
37
  return twolists(source_lines, generated_lines)
38
 
39
 
40
  def add_to_lines(new_line):
41
- print("____new_line")
42
- print(new_line)
43
  source_lines.append(new_line)
44
- # NOTE: pass the whole array of line to the generator
45
  # There is a compounding of the effect, a spiral of interaction.
46
  poem = build_poem(source_lines, generated_lines)
47
 
48
- print("__poem")
49
- print(poem)
50
-
51
- # pass the full poem into the generator
52
- result = generator("".join(poem), max_length=30, num_return_sequences=3)
53
- # result = generator(poem, max_length=30, num_return_sequences=3)
54
-
55
- print("____result")
56
- print(result[0]["generated_text"])
57
-
58
  response = result[0]["generated_text"]
59
 
60
- # TODO: remove each source_line from the poem
61
- response = response.replace("".join(poem), "")
62
-
63
- print("____response")
64
- print(response)
65
 
66
  generated_lines.append(response)
67
 
68
- # html = [f"<p>{line}</p>" for line in build_poem(source_lines, generated_lines)]
69
- html = [f"{line}<br/>" for line in build_poem(source_lines, generated_lines)]
 
 
 
 
 
 
 
70
 
71
  return html
72
 
 
25
  return newlist
26
 
27
 
 
28
  def build_poem(source_lines, generated_lines):
29
+ # This function structures the space already, set boundarys to the possible.
30
  # return a list with the two lists interspersed
 
 
 
 
 
 
31
  return twolists(source_lines, generated_lines)
32
 
33
 
34
  def add_to_lines(new_line):
 
 
35
  source_lines.append(new_line)
36
+ # NOTE: pass the whole array of lines to the generator
37
  # There is a compounding of the effect, a spiral of interaction.
38
  poem = build_poem(source_lines, generated_lines)
39
 
40
+ # pass the last two lines of the poem
41
+ prompt = "\n".join(poem[-2:])
42
+ result = generator(prompt, max_length=50, num_return_sequences=3)
 
 
 
 
 
 
 
43
  response = result[0]["generated_text"]
44
 
45
+ # Get only the new generated text
46
+ response = response.replace(prompt, "")
 
 
 
47
 
48
  generated_lines.append(response)
49
 
50
+ lines = []
51
+ for line in build_poem(source_lines, generated_lines):
52
+ if (len(lines) % 2) == 1:
53
+ line = f"<p style='text-align: right;'>{line}</p>"
54
+ else:
55
+ line = f"<p>{line}</p>"
56
+ lines.append(line)
57
+
58
+ html = "".join(lines)
59
 
60
  return html
61