Chris4K commited on
Commit
eceeded
·
verified ·
1 Parent(s): e16ddb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -2
app.py CHANGED
@@ -1,4 +1,49 @@
1
- from transformers.tools.base import launch_gradio_demo
2
  from text_generator import TextGenerationTool
3
 
4
- launch_gradio_demo(TextGenerationTool)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from text_generator import TextGenerationTool
2
 
3
+ # Create an instance of the tool
4
+ text_gen_tool = TextGenerationTool()
5
+
6
+ # Launch the Gradio interface
7
+ if __name__ == "__main__":
8
+ import gradio as gr
9
+
10
+ with gr.Blocks(title="Text Generation Tool") as demo:
11
+ gr.Markdown("# Text Generation Tool")
12
+
13
+ with gr.Row():
14
+ with gr.Column():
15
+ prompt_input = gr.Textbox(
16
+ label="Enter your prompt",
17
+ placeholder="Write a short story about a robot learning to paint.",
18
+ lines=5
19
+ )
20
+
21
+ with gr.Row():
22
+ generate_btn = gr.Button("Generate Text")
23
+ clear_btn = gr.Button("Clear")
24
+
25
+ with gr.Column():
26
+ output = gr.Textbox(label="Generated Text", lines=15)
27
+
28
+ generate_btn.click(
29
+ fn=text_gen_tool,
30
+ inputs=prompt_input,
31
+ outputs=output
32
+ )
33
+
34
+ clear_btn.click(
35
+ fn=lambda: ("", ""),
36
+ inputs=None,
37
+ outputs=[prompt_input, output]
38
+ )
39
+
40
+ gr.Examples(
41
+ examples=[
42
+ ["Write a short story about a robot learning to paint."],
43
+ ["Explain quantum computing to a 10-year-old."],
44
+ ["Write a poem about the changing seasons."]
45
+ ],
46
+ inputs=prompt_input
47
+ )
48
+
49
+ demo.launch(share=True)