Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -59,12 +59,12 @@ def generate_beam_html(index, all_beams_data, dark_mode):
|
|
| 59 |
return main_html, detail_html
|
| 60 |
|
| 61 |
@spaces.GPU
|
| 62 |
-
def predict(prompt, dark_mode):
|
| 63 |
"""
|
| 64 |
Generates responses for 5 beams and returns the first beam's visualization and visibility for controls.
|
| 65 |
"""
|
| 66 |
# Generate beams
|
| 67 |
-
generated_dicts, transcription = make_beams(model, processor, prompt)
|
| 68 |
|
| 69 |
# Get tokens and scores for all beams
|
| 70 |
beam_tokens = get_beam_tokens(generated_dicts, processor)
|
|
@@ -107,12 +107,19 @@ with gr.Blocks() as demo:
|
|
| 107 |
gr.Markdown('''Input a prompt. The model will:
|
| 108 |
- Generate multiple beams (a beam is a possible output generated by the model).
|
| 109 |
- Display the first output beam, highlighting any word or parts of words (tokens) with a probability score < 0.6 in red.
|
|
|
|
| 110 |
- Provide a toggle button to view detailed word/token probabilities for the beam.
|
| 111 |
''')
|
| 112 |
|
| 113 |
with gr.Column():
|
| 114 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", lines=1, show_label=True)
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
submit_btn = gr.Button("Generate")
|
| 117 |
|
| 118 |
output_html = gr.HTML(label="Highlighted Beam")
|
|
@@ -143,12 +150,12 @@ with gr.Blocks() as demo:
|
|
| 143 |
# Trigger generation on both button click and Enter key in textbox
|
| 144 |
submit_btn.click(
|
| 145 |
fn=predict,
|
| 146 |
-
inputs=[prompt_input, dark_mode_toggle],
|
| 147 |
outputs=[output_html, detail_html, toggle_btn, next_beam_btn, all_beams_state, current_beam_state]
|
| 148 |
)
|
| 149 |
prompt_input.submit(
|
| 150 |
fn=predict,
|
| 151 |
-
inputs=[prompt_input, dark_mode_toggle],
|
| 152 |
outputs=[output_html, detail_html, toggle_btn, next_beam_btn, all_beams_state, current_beam_state]
|
| 153 |
)
|
| 154 |
|
|
|
|
| 59 |
return main_html, detail_html
|
| 60 |
|
| 61 |
@spaces.GPU
|
| 62 |
+
def predict(prompt, dark_mode, temperature):
|
| 63 |
"""
|
| 64 |
Generates responses for 5 beams and returns the first beam's visualization and visibility for controls.
|
| 65 |
"""
|
| 66 |
# Generate beams
|
| 67 |
+
generated_dicts, transcription = make_beams(model, processor, prompt, temperature=temperature)
|
| 68 |
|
| 69 |
# Get tokens and scores for all beams
|
| 70 |
beam_tokens = get_beam_tokens(generated_dicts, processor)
|
|
|
|
| 107 |
gr.Markdown('''Input a prompt. The model will:
|
| 108 |
- Generate multiple beams (a beam is a possible output generated by the model).
|
| 109 |
- Display the first output beam, highlighting any word or parts of words (tokens) with a probability score < 0.6 in red.
|
| 110 |
+
- These unconfident words/tokens can be considered inflection points, or places where the output could change easily.
|
| 111 |
- Provide a toggle button to view detailed word/token probabilities for the beam.
|
| 112 |
''')
|
| 113 |
|
| 114 |
with gr.Column():
|
| 115 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", lines=1, show_label=True)
|
| 116 |
+
with gr.Row():
|
| 117 |
+
dark_mode_toggle = gr.Checkbox(label="Dark Mode", value=True)
|
| 118 |
+
temp_radio = gr.Radio(
|
| 119 |
+
label="Temperature",
|
| 120 |
+
choices=[0.0, 0.5, 1.0, 1.5],
|
| 121 |
+
value=1.0
|
| 122 |
+
)
|
| 123 |
submit_btn = gr.Button("Generate")
|
| 124 |
|
| 125 |
output_html = gr.HTML(label="Highlighted Beam")
|
|
|
|
| 150 |
# Trigger generation on both button click and Enter key in textbox
|
| 151 |
submit_btn.click(
|
| 152 |
fn=predict,
|
| 153 |
+
inputs=[prompt_input, dark_mode_toggle, temp_radio],
|
| 154 |
outputs=[output_html, detail_html, toggle_btn, next_beam_btn, all_beams_state, current_beam_state]
|
| 155 |
)
|
| 156 |
prompt_input.submit(
|
| 157 |
fn=predict,
|
| 158 |
+
inputs=[prompt_input, dark_mode_toggle, temp_radio],
|
| 159 |
outputs=[output_html, detail_html, toggle_btn, next_beam_btn, all_beams_state, current_beam_state]
|
| 160 |
)
|
| 161 |
|