BusinessDev commited on
Commit
7e21dc1
1 Parent(s): 19284c7
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,8 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
 
6
 
7
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
8
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the text generation model
5
+ model_id = "gpt2" # You can replace this with any model of your choice
6
+ generator = pipeline("text-generation", model=model_id)
7
 
8
+ # Define the function to process the input and generate text
9
+ def generate_text(prompt):
10
+ response = generator(prompt, max_length=50, num_return_sequences=1)
11
+ generated_text = response[0]['generated_text']
12
+ return generated_text
13
+
14
+ # Create the Gradio interface
15
+ iface = gr.Interface(
16
+ fn=generate_text,
17
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
18
+ outputs="text",
19
+ title="Text Generation",
20
+ description="Enter a prompt and the model will generate text based on it."
21
+ )
22
+
23
+ # Launch the interface
24
+ if __name__ == "__main__":
25
+ iface.launch()