Amitesh007 commited on
Commit
ca454fe
·
verified ·
1 Parent(s): fce286f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -20
app.py CHANGED
@@ -1,28 +1,36 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  fine_tuned_model = "Amitesh007/text_generation-finetuned-gpt2"
5
- def generate(text):
6
- generator = pipeline('text-generation', model=fine_tuned_model)
7
- result = generator(text, num_return_sequences=2,
8
- max_length=100
9
-
10
- )
11
- return result[0]["generated_text"],result[1]["generated_text"]
12
 
13
- Examples = [["A light snow had fallen the night before, and there were"],["The pig face had been smashed in with a mace, but Tyrion"]]
 
 
14
 
15
- demo = gr.Interface(
16
- fn=generate,
17
- inputs=[gr.Textbox(lines=5, label="Input Text here....")],
18
- outputs=[
19
- gr.Textbox(label="Generated Text 1"),
20
- gr.Textbox(label="Generated Text 2")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- ],
23
- title = "Text Generator GPT2 Pipeline",
24
- description = "this is a fine-tuned base gpt2 model inference, trained on a small 'game of thrones' dataset",
25
- examples = Examples
26
- )
27
  demo.queue(concurrency_count=2)
28
- demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Define the model and the text generation function
5
  fine_tuned_model = "Amitesh007/text_generation-finetuned-gpt2"
6
+ generator = pipeline('text-generation', model=fine_tuned_model)
 
 
 
 
 
 
7
 
8
+ def generate(text):
9
+ results = generator(text, num_return_sequences=2, max_length=100)
10
+ return results[0]["generated_text"], results[1]["generated_text"]
11
 
12
+ # Create the Gradio Blocks interface
13
+ with gr.Blocks() as demo:
14
+ gr.Markdown("# Text Generator GPT2 Pipeline")
15
+ gr.Markdown("This is a fine-tuned base GPT2 model inference, trained on a small 'Game of Thrones' dataset.")
16
+
17
+ with gr.Row():
18
+ with gr.Column():
19
+ input_text = gr.Textbox(lines=5, label="Input Text here....", placeholder="Type a sentence to start generating text")
20
+ generate_button = gr.Button("Generate")
21
+
22
+ with gr.Column():
23
+ output_text1 = gr.Textbox(label="Generated Text 1")
24
+ output_text2 = gr.Textbox(label="Generated Text 2")
25
+
26
+ examples = gr.Examples(
27
+ examples=[["A light snow had fallen the night before, and there were"],
28
+ ["The pig face had been smashed in with a mace, but Tyrion"]],
29
+ inputs=input_text
30
+ )
31
+
32
+ generate_button.click(fn=generate, inputs=input_text, outputs=[output_text1, output_text2])
33
 
34
+ # Launch the interface
 
 
 
 
35
  demo.queue(concurrency_count=2)
36
+ demo.launch()