Shangkhonil commited on
Commit
72230ff
·
verified ·
1 Parent(s): c300918

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the text generation pipeline with the GPT-2 model
5
+ pipe = pipeline("text-generation", model="openai-community/gpt2")
6
+
7
+ def generate_text(prompt):
8
+ # Generate text using the pipeline
9
+ result = pipe(prompt, max_length=100, num_return_sequences=1)
10
+ return result[0]['generated_text']
11
+
12
+ # Create Gradio interface
13
+ title = "GPT-2 Text Generation"
14
+ description = "Generate text based on a prompt using the GPT-2 model."
15
+
16
+ interface = gr.Interface(
17
+ fn=generate_text,
18
+ inputs=gr.Textbox(label="Enter your prompt"),
19
+ outputs=gr.Textbox(label="Generated Text"),
20
+ title=title,
21
+ description=description,
22
+ )
23
+
24
+ # Launch the Gradio app
25
+ if __name__ == "__main__":
26
+ interface.launch()