Keerthi Balaji commited on
Commit
40a6377
1 Parent(s): 60634a6

wrote the code for text generation

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ generator = pipeline("text-generation", model="gpt2")
5
+
6
+ def generate_prompt(topic):
7
+ prompt = f"Write a creative story about {topic}. Here is a prompt to get you started:"
8
+ result = generator(prompt, max_length=50, num_return_sequences=1)
9
+ return result[0]['generated_text']
10
+
11
+ iface = gr.Interface(
12
+ fn=generate_prompt,
13
+ input="text",
14
+ output="text",
15
+ title="Creative Writing Prompt Generation",
16
+ )
17
+
18
+ iface.launch()