Upload 2 files
Browse files- app.py +30 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""app.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1-t9RYzLIxj4UDdky3Q_wyg29YwrPfJZN
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import gradio as gr
|
| 11 |
+
from transformers import pipeline
|
| 12 |
+
|
| 13 |
+
generator = pipeline("text-generation", model="gpt2")
|
| 14 |
+
|
| 15 |
+
def generate_text(prompt):
|
| 16 |
+
output = generator(prompt, max_new_tokens=50, do_sample=True, return_full_text=False)
|
| 17 |
+
return output[0]["generated_text"]
|
| 18 |
+
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=generate_text,
|
| 21 |
+
inputs=gr.Textbox(lines=4, placeholder="Type a short prompt here..."),
|
| 22 |
+
outputs=gr.Textbox(lines=4, label="Output"),
|
| 23 |
+
allow_flagging="never",
|
| 24 |
+
title="Text Generator Demo",
|
| 25 |
+
description="A simple Gradio app using GPT-2 from Hugging Face Transformers.",
|
| 26 |
+
theme="soft",
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
demo.queue().launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4
|
| 2 |
+
transformers>=4.40
|
| 3 |
+
accelerate
|
| 4 |
+
torch
|