Download app.py from sr5434/Explainer: direct link, hf CLI and curl.
- Browser
- Download file 868 Bytes
-
https://huggingface.co/spaces/sr5434/Explainer/resolve/main/app.py
- Command line
-
hf download hf://spaces/sr5434/Explainer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sr5434/Explainer/resolve/main/app.py
868 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Define the function that will process the text | |
| def generate_text(prompt1, prompt2): | |
| # Define the GPT-2 model and the processing pipeline | |
| model = "EleutherAI/gpt-neo-125M" | |
| summarization = pipeline("text-generation", model=model) | |
| # Concatenate the two prompts | |
| prompt = "Explain " + prompt1 + " to a " + prompt2 + " grader below." | |
| # Generate the text | |
| result = summarization(prompt, max_length=32) | |
| return result[0]["generated_text"] | |
| # Create the input interface | |
| inputs = [gr.inputs.Textbox(lines=5, label="Prompt 1:"), gr.inputs.Textbox(lines=5, label="Prompt 2:")] | |
| # Create the output interface | |
| outputs = gr.outputs.Textbox(label="Generated Text") | |
| # Create the app | |
| app = gr.Interface(generate_text, inputs, outputs, title="GPT-2 Text Generation Demo") | |
| # Run the app | |
| app.launch() |