Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import torch
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import gradio as gr
|
4 |
|
|
|
5 |
# Load pre-trained GPT-2 model and tokenizer
|
6 |
model_name = "gpt2-large"
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
@@ -50,9 +51,8 @@ def generate_text_with_nucleus_search(input_text, max_length=16, do_sample=True,
|
|
50 |
# Create Gradio input interface
|
51 |
input_text_interface = gr.Textbox(lines=5, label="Input Text", placeholder="Enter text for generation...")
|
52 |
|
53 |
-
# Create Gradio output
|
54 |
output_text_interface1 = gr.Textbox(label="Generated Text (Regular)", placeholder="Generated text will appear here...")
|
55 |
-
output_text_interface2 = gr.Textbox(label="Generated Text (Nucleus Sampling)", placeholder="Generated text will appear here...")
|
56 |
|
57 |
# Interface for regular text generation
|
58 |
interface1 = gr.Interface(generate_text, input_text_interface, output_text_interface1,
|
@@ -60,6 +60,9 @@ interface1 = gr.Interface(generate_text, input_text_interface, output_text_inter
|
|
60 |
description="Generate text using the GPT-2 model with regular generation method.",
|
61 |
allow_flagging="never")
|
62 |
|
|
|
|
|
|
|
63 |
# Interface for text generation with nucleus sampling
|
64 |
interface2 = gr.Interface(generate_text_with_nucleus_search, input_text_interface, output_text_interface2,
|
65 |
title="Text Generation with Nucleus Sampling",
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import gradio as gr
|
4 |
|
5 |
+
|
6 |
# Load pre-trained GPT-2 model and tokenizer
|
7 |
model_name = "gpt2-large"
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
51 |
# Create Gradio input interface
|
52 |
input_text_interface = gr.Textbox(lines=5, label="Input Text", placeholder="Enter text for generation...")
|
53 |
|
54 |
+
# Create Gradio output interface for regular text generation
|
55 |
output_text_interface1 = gr.Textbox(label="Generated Text (Regular)", placeholder="Generated text will appear here...")
|
|
|
56 |
|
57 |
# Interface for regular text generation
|
58 |
interface1 = gr.Interface(generate_text, input_text_interface, output_text_interface1,
|
|
|
60 |
description="Generate text using the GPT-2 model with regular generation method.",
|
61 |
allow_flagging="never")
|
62 |
|
63 |
+
# Create Gradio output interface for text generation with nucleus sampling
|
64 |
+
output_text_interface2 = gr.Textbox(label="Generated Text (Nucleus Sampling)", placeholder="Generated text will appear here...")
|
65 |
+
|
66 |
# Interface for text generation with nucleus sampling
|
67 |
interface2 = gr.Interface(generate_text_with_nucleus_search, input_text_interface, output_text_interface2,
|
68 |
title="Text Generation with Nucleus Sampling",
|