rahul7star commited on
Commit
e579029
·
verified ·
1 Parent(s): df3a0f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -45,7 +45,6 @@ def generate_poetry(prompt, max_length=100, temperature=0.7, top_k=50, top_p=0.9
45
  return tokenizer.decode(output[0], skip_special_tokens=True)
46
 
47
  # Poetry Generation Function with Random Selection from Dataset and Explicit 4-Line Structure
48
- # Modify the generate_random_poem function to handle inputs from Gradio
49
  def generate_random_poem(prompt, max_length=150, temperature=1.0, top_p=0.9, num_lines=4):
50
  # Randomly select a line from the dataset
51
  random_line = random.choice(dataset["poem"])
@@ -76,18 +75,14 @@ def generate_random_poem(prompt, max_length=150, temperature=1.0, top_p=0.9, num
76
  pad_token_id=pad_token_id
77
  )
78
 
79
- # Decode the output and split into lines using punctuation or newlines
80
  generated_poem = tokenizer.decode(output[0], skip_special_tokens=True)
81
  generated_poem = generated_poem.strip()
82
 
83
- # Split the generated text into separate lines based on punctuation or line breaks
84
- #poem_lines = generated_poem.split("।") # Hindi poems often end with "।" (full stop)
85
- poem_lines = 4 # Ensure num_lines is an integer
86
 
87
-
88
-
89
- num_lines = int(num_lines)
90
- # Ensure that we have exactly 4 lines
91
  if len(poem_lines) < num_lines:
92
  while len(poem_lines) < num_lines:
93
  # If not enough lines, add more content from the dataset
@@ -117,4 +112,3 @@ interface = gr.Interface(
117
 
118
  # 4️⃣ Run the Gradio App
119
  interface.launch(share=True)
120
-
 
45
  return tokenizer.decode(output[0], skip_special_tokens=True)
46
 
47
  # Poetry Generation Function with Random Selection from Dataset and Explicit 4-Line Structure
 
48
  def generate_random_poem(prompt, max_length=150, temperature=1.0, top_p=0.9, num_lines=4):
49
  # Randomly select a line from the dataset
50
  random_line = random.choice(dataset["poem"])
 
75
  pad_token_id=pad_token_id
76
  )
77
 
78
+ # Decode the output and split into lines
79
  generated_poem = tokenizer.decode(output[0], skip_special_tokens=True)
80
  generated_poem = generated_poem.strip()
81
 
82
+ # Split the generated text into separate lines based on full stops (Hindi poems often end with "।")
83
+ poem_lines = generated_poem.split("।")
 
84
 
85
+ # Ensure we have exactly num_lines (4 by default)
 
 
 
86
  if len(poem_lines) < num_lines:
87
  while len(poem_lines) < num_lines:
88
  # If not enough lines, add more content from the dataset
 
112
 
113
  # 4️⃣ Run the Gradio App
114
  interface.launch(share=True)