Spaces:
Running
Running
Update app.py
Browse filesUpgrade to smolagents
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 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__":
|
|
@@ -18,6 +18,12 @@ if __name__ == "__main__":
|
|
| 18 |
lines=5
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
with gr.Row():
|
| 22 |
generate_btn = gr.Button("Generate Text")
|
| 23 |
clear_btn = gr.Button("Clear")
|
|
@@ -25,25 +31,28 @@ if __name__ == "__main__":
|
|
| 25 |
with gr.Column():
|
| 26 |
output = gr.Textbox(label="Generated Text", lines=15)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
generate_btn.click(
|
| 29 |
-
fn=
|
| 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)
|
|
|
|
| 1 |
from text_generator import TextGenerationTool
|
| 2 |
|
| 3 |
# Create an instance of the tool
|
| 4 |
+
text_gen_tool = TextGenerationTool(default_model="gpt2")
|
| 5 |
|
| 6 |
# Launch the Gradio interface
|
| 7 |
if __name__ == "__main__":
|
|
|
|
| 18 |
lines=5
|
| 19 |
)
|
| 20 |
|
| 21 |
+
model_dropdown = gr.Dropdown(
|
| 22 |
+
choices=list(text_gen_tool.models.keys()),
|
| 23 |
+
value=text_gen_tool.default_model,
|
| 24 |
+
label="Select Model"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
with gr.Row():
|
| 28 |
generate_btn = gr.Button("Generate Text")
|
| 29 |
clear_btn = gr.Button("Clear")
|
|
|
|
| 31 |
with gr.Column():
|
| 32 |
output = gr.Textbox(label="Generated Text", lines=15)
|
| 33 |
|
| 34 |
+
def generate_with_model(prompt, model_key):
|
| 35 |
+
return text_gen_tool.generate_text(prompt, model_key)
|
| 36 |
+
|
| 37 |
generate_btn.click(
|
| 38 |
+
fn=generate_with_model,
|
| 39 |
+
inputs=[prompt_input, model_dropdown],
|
| 40 |
outputs=output
|
| 41 |
)
|
| 42 |
|
| 43 |
clear_btn.click(
|
| 44 |
+
fn=lambda: ("", None),
|
| 45 |
inputs=None,
|
| 46 |
outputs=[prompt_input, output]
|
| 47 |
)
|
| 48 |
|
| 49 |
gr.Examples(
|
| 50 |
examples=[
|
| 51 |
+
["Write a short story about a robot learning to paint.", "gpt2"],
|
| 52 |
+
["Explain quantum computing to a 10-year-old.", "gpt2"],
|
| 53 |
+
["Write a poem about the changing seasons.", "gpt2"]
|
| 54 |
],
|
| 55 |
+
inputs=[prompt_input, model_dropdown]
|
| 56 |
)
|
| 57 |
|
| 58 |
demo.launch(share=True)
|