ajeetkumar01 commited on
Commit
cf5c142
·
verified ·
1 Parent(s): ed9a903

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -14,14 +14,12 @@ model = AutoModelForCausalLM.from_pretrained(model_name)
14
  def generate_text(input_text, max_length=16, num_beams=5, do_sample=False, no_repeat_ngram_size=2):
15
  """
16
  Generate text based on the given input text.
17
-
18
  Parameters:
19
  - input_text (str): The input text to start generation from.
20
  - max_length (int): Maximum length of the generated text.
21
  - num_beams (int): Number of beams for beam search.
22
  - do_sample (bool): Whether to use sampling or not.
23
  - no_repeat_ngram_size (int): Size of the n-gram to avoid repetition.
24
-
25
  Returns:
26
  - generated_text (str): The generated text.
27
  """
@@ -38,13 +36,11 @@ def generate_text(input_text, max_length=16, num_beams=5, do_sample=False, no_re
38
  def generate_text_with_nucleus_search(input_text, max_length=16, do_sample=True, top_p=0.9):
39
  """
40
  Generate text with nucleus sampling based on the given input text.
41
-
42
  Parameters:
43
  - input_text (str): The input text to start generation from.
44
  - max_length (int): Maximum length of the generated text.
45
  - do_sample (bool): Whether to use sampling or not.
46
  - top_p (float): Nucleus sampling parameter.
47
-
48
  Returns:
49
  - generated_text (str): The generated text.
50
  """
@@ -60,11 +56,19 @@ def generate_text_with_nucleus_search(input_text, max_length=16, do_sample=True,
60
  # Create Gradio interface
61
  input_text = gr.Textbox(lines=10, label="Input Text", placeholder="Enter text for text generation...")
62
  output_text1 = gr.Textbox(label="Generated Text")
63
- output_text2 = gr.Textbox(label="generate_text_with_nucleus_search")
64
 
 
 
 
 
 
 
 
65
 
66
- gr.Interface(generate_text, input_text, output_text1,output_text2,
67
  title="Text Generation with GPT-2",
68
  description="Generate text using the GPT-2 model.",
69
  theme="default", # Change theme to default
70
- allow_flagging="never").launch(share=True)
 
 
14
  def generate_text(input_text, max_length=16, num_beams=5, do_sample=False, no_repeat_ngram_size=2):
15
  """
16
  Generate text based on the given input text.
 
17
  Parameters:
18
  - input_text (str): The input text to start generation from.
19
  - max_length (int): Maximum length of the generated text.
20
  - num_beams (int): Number of beams for beam search.
21
  - do_sample (bool): Whether to use sampling or not.
22
  - no_repeat_ngram_size (int): Size of the n-gram to avoid repetition.
 
23
  Returns:
24
  - generated_text (str): The generated text.
25
  """
 
36
  def generate_text_with_nucleus_search(input_text, max_length=16, do_sample=True, top_p=0.9):
37
  """
38
  Generate text with nucleus sampling based on the given input text.
 
39
  Parameters:
40
  - input_text (str): The input text to start generation from.
41
  - max_length (int): Maximum length of the generated text.
42
  - do_sample (bool): Whether to use sampling or not.
43
  - top_p (float): Nucleus sampling parameter.
 
44
  Returns:
45
  - generated_text (str): The generated text.
46
  """
 
56
  # Create Gradio interface
57
  input_text = gr.Textbox(lines=10, label="Input Text", placeholder="Enter text for text generation...")
58
  output_text1 = gr.Textbox(label="Generated Text")
59
+ output_text2 = gr.Textbox(label="Generated Text with Nucleus Search")
60
 
61
+ # Set examples to None or empty list if not available
62
+ examples = [
63
+ ["I am happy."],
64
+ ["This is a good day."],
65
+ ["It is raining outside."],
66
+ None # Example for output_text2
67
+ ]
68
 
69
+ gr.Interface(generate_text, input_text, output_text1, output_text2,
70
  title="Text Generation with GPT-2",
71
  description="Generate text using the GPT-2 model.",
72
  theme="default", # Change theme to default
73
+ allow_flagging="never",
74
+ examples=examples).launch(share=True)