Tonic commited on
Commit
3582cae
·
verified ·
1 Parent(s): d153be5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -19,7 +19,7 @@ model.to(device)
19
 
20
  # Load spaCy model for dependency parsing
21
  os.system('python -m spacy download en_core_web_sm')
22
- nlp = spacy.load("en_core_web_sm") ## add latin-spacy
23
 
24
  # Function for generating text and tokenizing
25
  def historical_generation(prompt, max_new_tokens=600):
@@ -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
 
@@ -92,7 +92,11 @@ def full_interface(prompt, max_new_tokens):
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:
@@ -108,6 +112,9 @@ with gr.Blocks() as iface:
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,
@@ -115,11 +122,19 @@ with gr.Blocks() as iface:
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()
 
19
 
20
  # Load spaCy model for dependency parsing
21
  os.system('python -m spacy download en_core_web_sm')
22
+ nlp = spacy.load("en_core_web_sm")
23
 
24
  # Function for generating text and tokenizing
25
  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("Ġ", "") # Remove "Ġ"
60
  token_type = tokenizer.convert_ids_to_tokens([tokenizer.convert_tokens_to_ids(token)])[0]
61
  highlighted_text.append((clean_token, token_type))
62
 
 
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, gr.update(visible=False), gr.update(visible=True)
96
+
97
+ # Reset function to restore button states
98
+ def reset_interface():
99
+ return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
100
 
101
  # Gradio interface components
102
  with gr.Blocks() as iface:
 
112
  send_button = gr.Button(value="Generate Dependency Parse for Generated Text", visible=False)
113
  dependency_parse_generated = gr.HTML(label="Dependency Parse Visualization (Generated Text)")
114
 
115
+ # Reset button, hidden initially
116
+ reset_button = gr.Button(value="Start Again", visible=False)
117
+
118
  # Button behavior for generating final parse visualization
119
  send_button.click(
120
  generate_dependency_parse,
 
122
  outputs=[dependency_parse_generated]
123
  )
124
 
125
+ # Main interface logic: when clicked, "Generate" button hides itself and shows the reset button
126
+ generate_button = gr.Button(value="Generate Text and Initial Outputs")
127
+ generate_button.click(
128
  full_interface,
129
  inputs=[prompt, max_new_tokens],
130
+ outputs=[highlighted_text, tokenizer_info, dependency_parse_input, send_button, dependency_parse_generated, generate_button, reset_button]
131
+ )
132
+
133
+ # Reset button logic: hide itself and re-show the "Generate" button
134
+ reset_button.click(
135
+ reset_interface,
136
+ inputs=None,
137
+ outputs=[generate_button, send_button, reset_button]
138
  )
139
 
140
+ iface.launch()