Spaces:
Running
Running
Create playground_utils.py
Browse files- playground_utils.py +60 -0
playground_utils.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from task import tasks_config
|
3 |
+
from pipeline_utils import handle_task_change, review_training_choices, test_pipeline
|
4 |
+
from playground_utils import create_playground_header, create_playground_footer, create_tabs_header
|
5 |
+
|
6 |
+
playground = gr.Blocks()
|
7 |
+
|
8 |
+
with playground:
|
9 |
+
create_playground_header()
|
10 |
+
with gr.Tabs():
|
11 |
+
with gr.TabItem("Text"):
|
12 |
+
radio, test_pipeline_button = create_tabs_header()
|
13 |
+
with gr.Row(visible=True) as use_pipeline:
|
14 |
+
with gr.Column():
|
15 |
+
task_dropdown = gr.Dropdown(
|
16 |
+
choices=[(task["name"], task_id)
|
17 |
+
for task_id, task in tasks_config.items()],
|
18 |
+
label="Task",
|
19 |
+
interactive=True,
|
20 |
+
info="Select Pipelines for natural language processing tasks or type if you have your own."
|
21 |
+
)
|
22 |
+
model_dropdown = gr.Dropdown(
|
23 |
+
[], label="Model", info="Select appropriate Model based on the task you selected")
|
24 |
+
prompt_textarea = gr.TextArea(
|
25 |
+
label="Prompt",
|
26 |
+
value="Enter your prompt here",
|
27 |
+
text_align="left",
|
28 |
+
info="Copy/Paste or type your prompt to try out. Make sure to provide clear prompt or try with different prompts"
|
29 |
+
)
|
30 |
+
context_for_question_answer = gr.TextArea(
|
31 |
+
label="Context",
|
32 |
+
value="Enter Context for your question here",
|
33 |
+
visible=False,
|
34 |
+
interactive=True,
|
35 |
+
info="Question answering tasks return an answer given a question. If you’ve ever asked a virtual assistant like Alexa, Siri or Google what the weather is, then you’ve used a question answering model before. Here, we are doing Extractive(extract the answer from the given context) Question answering. "
|
36 |
+
)
|
37 |
+
task_dropdown.change(handle_task_change,
|
38 |
+
inputs=[task_dropdown],
|
39 |
+
outputs=[context_for_question_answer,
|
40 |
+
model_dropdown, task_dropdown])
|
41 |
+
with gr.Column():
|
42 |
+
text = gr.TextArea(label="Generated Text")
|
43 |
+
radio.change(review_training_choices,
|
44 |
+
inputs=radio, outputs=use_pipeline)
|
45 |
+
test_pipeline_button.click(test_pipeline,
|
46 |
+
inputs=[
|
47 |
+
task_dropdown, model_dropdown, prompt_textarea, context_for_question_answer],
|
48 |
+
outputs=text)
|
49 |
+
with gr.TabItem("Image"):
|
50 |
+
radio, test_pipeline_button = create_tabs_header()
|
51 |
+
gr.Markdown("""
|
52 |
+
> WIP
|
53 |
+
""")
|
54 |
+
with gr.TabItem("Audio"):
|
55 |
+
radio, test_pipeline_button = create_tabs_header()
|
56 |
+
gr.Markdown("""
|
57 |
+
> WIP
|
58 |
+
""")
|
59 |
+
create_playground_footer()
|
60 |
+
playground.launch()
|