Spaces:
Build error
Build error
Debugging app.py as rewritten by ChatGPT-4o
#1
by
Addaci
- opened
app.py
CHANGED
@@ -10,10 +10,6 @@ model_id = "google/flan-t5-small"
|
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
12 |
|
13 |
-
# Define the sliders outside the gr.Row() block
|
14 |
-
max_new_tokens = gr.Slider(minimum=10, maximum=512, value=360, step=1, label="Max New Tokens") # Adjusted for smaller model
|
15 |
-
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
|
16 |
-
|
17 |
def correct_htr(raw_htr_text, max_new_tokens, temperature):
|
18 |
try:
|
19 |
if not raw_htr_text:
|
@@ -98,6 +94,11 @@ with gr.Blocks() as demo:
|
|
98 |
</div>
|
99 |
''')
|
100 |
|
|
|
|
|
|
|
|
|
|
|
101 |
with gr.Tab("Correct HTR"):
|
102 |
gr.Markdown("### Correct Raw HTR Text")
|
103 |
raw_htr_input = gr.Textbox(lines=5, placeholder="Enter raw HTR text here...")
|
@@ -105,7 +106,7 @@ with gr.Blocks() as demo:
|
|
105 |
correct_button = gr.Button("Correct HTR")
|
106 |
clear_button = gr.Button("Clear")
|
107 |
|
108 |
-
correct_button.click(correct_htr, inputs=[raw_htr_input,
|
109 |
clear_button.click(clear_fields, outputs=[raw_htr_input, corrected_output])
|
110 |
|
111 |
with gr.Tab("Summarize Legal Text"):
|
@@ -115,7 +116,7 @@ with gr.Blocks() as demo:
|
|
115 |
summarize_button = gr.Button("Summarize Text")
|
116 |
clear_button = gr.Button("Clear")
|
117 |
|
118 |
-
summarize_button.click(summarize_text, inputs=[legal_text_input,
|
119 |
clear_button.click(clear_fields, outputs=[legal_text_input, summary_output])
|
120 |
|
121 |
with gr.Tab("Answer Legal Question"):
|
@@ -126,18 +127,12 @@ with gr.Blocks() as demo:
|
|
126 |
answer_button = gr.Button("Get Answer")
|
127 |
clear_button = gr.Button("Clear")
|
128 |
|
129 |
-
answer_button.click(answer_question, inputs=[legal_text_input_q, question_input,
|
130 |
clear_button.click(clear_fields, outputs=[legal_text_input_q, question_input, answer_output])
|
131 |
|
132 |
-
# The sliders are already defined, so just include them in the layout
|
133 |
-
with gr.Row():
|
134 |
-
# No need to redefine max_new_tokens and temperature here
|
135 |
-
pass
|
136 |
-
|
137 |
# Model warm-up (optional, but useful for performance)
|
138 |
model.generate(**tokenizer("Warm-up", return_tensors="pt"), max_length=10)
|
139 |
|
140 |
# Launch the Gradio interface
|
141 |
if __name__ == "__main__":
|
142 |
-
demo.launch()
|
143 |
-
|
|
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
12 |
|
|
|
|
|
|
|
|
|
13 |
def correct_htr(raw_htr_text, max_new_tokens, temperature):
|
14 |
try:
|
15 |
if not raw_htr_text:
|
|
|
94 |
</div>
|
95 |
''')
|
96 |
|
97 |
+
# Sliders for max_new_tokens and temperature
|
98 |
+
with gr.Row():
|
99 |
+
max_new_tokens_slider = gr.Slider(minimum=10, maximum=512, value=128, step=1, label="Max New Tokens")
|
100 |
+
temperature_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
|
101 |
+
|
102 |
with gr.Tab("Correct HTR"):
|
103 |
gr.Markdown("### Correct Raw HTR Text")
|
104 |
raw_htr_input = gr.Textbox(lines=5, placeholder="Enter raw HTR text here...")
|
|
|
106 |
correct_button = gr.Button("Correct HTR")
|
107 |
clear_button = gr.Button("Clear")
|
108 |
|
109 |
+
correct_button.click(correct_htr, inputs=[raw_htr_input, max_new_tokens_slider, temperature_slider], outputs=corrected_output)
|
110 |
clear_button.click(clear_fields, outputs=[raw_htr_input, corrected_output])
|
111 |
|
112 |
with gr.Tab("Summarize Legal Text"):
|
|
|
116 |
summarize_button = gr.Button("Summarize Text")
|
117 |
clear_button = gr.Button("Clear")
|
118 |
|
119 |
+
summarize_button.click(summarize_text, inputs=[legal_text_input, max_new_tokens_slider, temperature_slider], outputs=summary_output)
|
120 |
clear_button.click(clear_fields, outputs=[legal_text_input, summary_output])
|
121 |
|
122 |
with gr.Tab("Answer Legal Question"):
|
|
|
127 |
answer_button = gr.Button("Get Answer")
|
128 |
clear_button = gr.Button("Clear")
|
129 |
|
130 |
+
answer_button.click(answer_question, inputs=[legal_text_input_q, question_input, max_new_tokens_slider, temperature_slider], outputs=answer_output)
|
131 |
clear_button.click(clear_fields, outputs=[legal_text_input_q, question_input, answer_output])
|
132 |
|
|
|
|
|
|
|
|
|
|
|
133 |
# Model warm-up (optional, but useful for performance)
|
134 |
model.generate(**tokenizer("Warm-up", return_tensors="pt"), max_length=10)
|
135 |
|
136 |
# Launch the Gradio interface
|
137 |
if __name__ == "__main__":
|
138 |
+
demo.launch()
|
|