Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Define the function that will process the text
|
5 |
+
def generate_text(prompt1, prompt2):
|
6 |
+
# Define the GPT-2 model and the processing pipeline
|
7 |
+
model = "EleutherAI/gpt-neo-125M"
|
8 |
+
summarization = pipeline("text-generation", model=model)
|
9 |
+
# Concatenate the two prompts
|
10 |
+
prompt = "Explain " + prompt1 + " to a " + prompt + " grader below."
|
11 |
+
# Generate the text
|
12 |
+
result = summarization(prompt, max_length=32)
|
13 |
+
return result[0]["generated_text"]
|
14 |
+
|
15 |
+
# Create the input interface
|
16 |
+
inputs = [gr.inputs.Textbox(lines=5, label="Prompt 1:"), gr.inputs.Textbox(lines=5, label="Prompt 2:")]
|
17 |
+
|
18 |
+
# Create the output interface
|
19 |
+
outputs = gr.outputs.Textbox(label="Generated Text")
|
20 |
+
|
21 |
+
# Create the app
|
22 |
+
app = gr.Interface(generate_text, inputs, outputs, title="GPT-2 Text Generation Demo")
|
23 |
+
|
24 |
+
# Run the app
|
25 |
+
app.launch()
|