Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,49 @@ import gradio as gr
|
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
import openai
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 7 |
|
|
|
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
import openai
|
| 4 |
import os
|
| 5 |
+
from transformers import pipline
|
| 6 |
+
|
| 7 |
+
generator = pipeline('text-generation', model='gpt2')
|
| 8 |
+
def generate_text(prompt):
|
| 9 |
+
outputs = generator(prompt, max_length=100, num_return_sequences=1)
|
| 10 |
+
return outputs[0]['generated_text']
|
| 11 |
+
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generator", description="Generate text using a pre-trained GPT-2 model.")
|
| 12 |
+
interface.launch()
|
| 13 |
+
interface = gr.Interface(
|
| 14 |
+
fn=generate_text,
|
| 15 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="GPT-2 Text Generator",
|
| 18 |
+
description="Generate text using the GPT-2 model from Hugging Face.",
|
| 19 |
+
theme="compact"
|
| 20 |
+
)
|
| 21 |
+
interface = gr.Interface(
|
| 22 |
+
fn=generate_text,
|
| 23 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 24 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 25 |
+
)
|
| 26 |
+
interface = gr.Interface(
|
| 27 |
+
fn=generate_text,
|
| 28 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 29 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 30 |
+
css=".output-textbox { border: 2px solid blue; }"
|
| 31 |
+
)
|
| 32 |
+
generator = pipeline('text-generation', model='gpt2')
|
| 33 |
+
|
| 34 |
+
def generate_text(prompt):
|
| 35 |
+
outputs = generator(prompt, max_length=50, num_return_sequences=1)
|
| 36 |
+
return outputs[0]['generated_text']
|
| 37 |
+
|
| 38 |
+
interface = gr.Interface(
|
| 39 |
+
fn=generate_text,
|
| 40 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 41 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 42 |
+
title="GPT-2 Text Generator",
|
| 43 |
+
description="Generate text using the GPT-2 model from Hugging Face."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
interface.launch()
|
| 48 |
|
| 49 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 50 |
|