Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,12 +45,12 @@ 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 |
-
def generate_random_poem(prompt, max_length=
|
49 |
# Randomly select a line from the dataset
|
50 |
random_line = random.choice(dataset["poem"])
|
51 |
|
52 |
# Prepare the input text with the random line selected, and start with a unique phrase to avoid repetition
|
53 |
-
input_text = f"
|
54 |
|
55 |
# Tokenize the input text
|
56 |
encoding = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True, max_length=max_length)
|
@@ -93,7 +93,7 @@ interface = gr.Interface(
|
|
93 |
fn=generate_random_poem, # Use function directly without calling it
|
94 |
inputs=[
|
95 |
gr.Textbox(label="Enter Prompt", placeholder="Start your Hindi poem..."),
|
96 |
-
gr.Slider(50, 500, step=10, value=
|
97 |
gr.Slider(0.1, 1.5, step=0.1, value=0.7, label="Temperature"),
|
98 |
gr.Slider(1, 100, step=1, value=50, label="Top-k Sampling"),
|
99 |
gr.Slider(0.1, 1.0, step=0.05, value=0.95, label="Top-p Sampling"),
|
|
|
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=180, 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"])
|
51 |
|
52 |
# Prepare the input text with the random line selected, and start with a unique phrase to avoid repetition
|
53 |
+
input_text = f"{random_line} " # Unique start to force variety
|
54 |
|
55 |
# Tokenize the input text
|
56 |
encoding = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True, max_length=max_length)
|
|
|
93 |
fn=generate_random_poem, # Use function directly without calling it
|
94 |
inputs=[
|
95 |
gr.Textbox(label="Enter Prompt", placeholder="Start your Hindi poem..."),
|
96 |
+
gr.Slider(50, 500, step=10, value=180, label="Max Length"),
|
97 |
gr.Slider(0.1, 1.5, step=0.1, value=0.7, label="Temperature"),
|
98 |
gr.Slider(1, 100, step=1, value=50, label="Top-k Sampling"),
|
99 |
gr.Slider(0.1, 1.0, step=0.05, value=0.95, label="Top-p Sampling"),
|