Eman-Abdelkader25 commited on
Commit
e23f61a
·
verified ·
1 Parent(s): 0a78af6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -1,24 +1,20 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the GPT-2 model .
5
- generator = pipeline('text-generation', model='gpt2')
6
 
7
- # Function to generate text
8
- def generate_text(prompt, max_length=50):
9
- return generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text']
 
10
 
11
  # Create the Gradio interface
12
  iface = gr.Interface(
13
  fn=generate_text,
14
- inputs=[
15
- gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
16
- gr.inputs.Slider(minimum=10, maximum=200, default=50, label="Max Length")
17
- ],
18
- outputs="text",
19
- title="GPT-2 Text Generator",
20
- description="Generate text using the GPT-2 model."
21
  )
22
 
23
- # Launch the app
24
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load a pre-trained Hugging Face model
5
+ generator = pipeline("text-generation", model="gpt2")
6
 
7
+ def generate_text(prompt):
8
+ # Generate text using the model
9
+ result = generator(prompt, max_length=50, num_return_sequences=1)
10
+ return result[0]["generated_text"]
11
 
12
  # Create the Gradio interface
13
  iface = gr.Interface(
14
  fn=generate_text,
15
+ inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
16
+ outputs=gr.Textbox()
 
 
 
 
 
17
  )
18
 
19
+ # Launch the interface
20
  iface.launch()