Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -56,7 +56,7 @@ def historical_generation(prompt, max_new_tokens=600):
|
|
56 |
# Create highlighted text output
|
57 |
highlighted_text = []
|
58 |
for token in tokens:
|
59 |
-
clean_token = token.replace("Ġ", "")
|
60 |
token_type = tokenizer.convert_ids_to_tokens([tokenizer.convert_tokens_to_ids(token)])[0]
|
61 |
highlighted_text.append((clean_token, token_type))
|
62 |
|
@@ -79,47 +79,47 @@ def text_analysis(text):
|
|
79 |
|
80 |
return pos_tokens, pos_count, html
|
81 |
|
82 |
-
#
|
|
|
|
|
|
|
|
|
|
|
83 |
def full_interface(prompt, max_new_tokens):
|
84 |
generated_highlight, generated_text = historical_generation(prompt, max_new_tokens)
|
85 |
|
86 |
-
# Dependency parse of
|
87 |
tokens_input, pos_count_input, html_input = text_analysis(prompt)
|
88 |
-
tokens_generated, pos_count_generated, html_generated = text_analysis(generated_text)
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
)
|
123 |
-
|
124 |
-
if __name__ == "__main__":
|
125 |
-
iface.launch()
|
|
|
56 |
# Create highlighted text output
|
57 |
highlighted_text = []
|
58 |
for token in tokens:
|
59 |
+
clean_token = token.replace("Ġ", "")
|
60 |
token_type = tokenizer.convert_ids_to_tokens([tokenizer.convert_tokens_to_ids(token)])[0]
|
61 |
highlighted_text.append((clean_token, token_type))
|
62 |
|
|
|
79 |
|
80 |
return pos_tokens, pos_count, html
|
81 |
|
82 |
+
# Function to generate dependency parse for generated text on button click
|
83 |
+
def generate_dependency_parse(generated_text):
|
84 |
+
tokens_generated, pos_count_generated, html_generated = text_analysis(generated_text)
|
85 |
+
return html_generated
|
86 |
+
|
87 |
+
# Full interface combining text generation and analysis, split across steps
|
88 |
def full_interface(prompt, max_new_tokens):
|
89 |
generated_highlight, generated_text = historical_generation(prompt, max_new_tokens)
|
90 |
|
91 |
+
# Dependency parse of input text
|
92 |
tokens_input, pos_count_input, html_input = text_analysis(prompt)
|
|
|
93 |
|
94 |
+
# The "Send" button should now appear after these outputs are generated
|
95 |
+
return generated_highlight, pos_count_input, html_input, gr.update(visible=True), generated_text
|
96 |
+
|
97 |
+
# Gradio interface components
|
98 |
+
with gr.Blocks() as iface:
|
99 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt for historical text generation...", lines=3)
|
100 |
+
max_new_tokens = gr.Slider(label="Max New Tokens", minimum=50, maximum=1000, step=50, value=600)
|
101 |
+
|
102 |
+
# Output components
|
103 |
+
highlighted_text = gr.HighlightedText(label="Generated Historical Text", combine_adjacent=True, show_legend=True)
|
104 |
+
tokenizer_info = gr.JSON(label="Tokenizer Info (Input Text)")
|
105 |
+
dependency_parse_input = gr.HTML(label="Dependency Parse Visualization (Input Text)")
|
106 |
+
|
107 |
+
# Hidden button and final output for dependency parse visualization
|
108 |
+
send_button = gr.Button(value="Generate Dependency Parse for Generated Text", visible=False)
|
109 |
+
dependency_parse_generated = gr.HTML(label="Dependency Parse Visualization (Generated Text)")
|
110 |
+
|
111 |
+
# Button behavior for generating final parse visualization
|
112 |
+
send_button.click(
|
113 |
+
generate_dependency_parse,
|
114 |
+
inputs=[dependency_parse_generated],
|
115 |
+
outputs=[dependency_parse_generated]
|
116 |
+
)
|
117 |
+
|
118 |
+
# Main interface logic
|
119 |
+
prompt.submit(
|
120 |
+
full_interface,
|
121 |
+
inputs=[prompt, max_new_tokens],
|
122 |
+
outputs=[highlighted_text, tokenizer_info, dependency_parse_input, send_button, dependency_parse_generated]
|
123 |
+
)
|
124 |
+
|
125 |
+
iface.launch()
|
|
|
|
|
|
|
|