Spaces:
Build error
Changed purpose of app.py to create gradio.Blocks interface
Browse filesExplanation of the Error:
#Nested Lists Not Allowed: Gradio's Interface does not support nested lists within inputs or outputs. Each element should be a single component (e.g., gr.Textbox, gr.Image), not a list of components.
#Multiple Functions Handling: When using multiple functions with different input/output configurations, the Interface class alone isn't sufficient.
Solution: Use Gradio's Blocks API
#To build a more complex interface that can handle multiple functions with varying numbers of inputs and outputs, you should use Gradio's Blocks API. This allows you to create a custom layout with multiple components and interactions.
Explanation of the Changes:
#Used gr.Blocks: This allows for a more flexible layout and supports complex interactions.
#Organized into Tabs:
Tab 1: "Correct HTR" with input raw_htr_input and output corrected_output.
Tab 2: "Summarize Legal Text" with input legal_text_input and output summary_output.
Tab 3: "Answer Legal Question" with inputs legal_text_input_q and question_input, and output answer_output.
Added Buttons: Each function is triggered by a button click, which calls the corresponding function.
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
|
@@ -36,22 +37,32 @@ def answer_question(legal_text, question):
|
|
36 |
|
37 |
return answer
|
38 |
|
39 |
-
# Create the Gradio interface
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
)
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
4 |
|
|
|
37 |
|
38 |
return answer
|
39 |
|
40 |
+
# Create the Gradio Blocks interface
|
41 |
+
with gr.Blocks() as demo:
|
42 |
+
gr.Markdown("# mT5 Legal Assistant")
|
43 |
+
gr.Markdown("Use this tool to correct raw HTR, summarize legal texts, or answer questions about legal cases.")
|
44 |
+
|
45 |
+
with gr.Tab("Correct HTR"):
|
46 |
+
gr.Markdown("### Correct Raw HTR Text")
|
47 |
+
raw_htr_input = gr.Textbox(lines=5, placeholder="Enter raw HTR text here...")
|
48 |
+
corrected_output = gr.Textbox(lines=5, placeholder="Corrected HTR text")
|
49 |
+
correct_button = gr.Button("Correct HTR")
|
50 |
+
correct_button.click(correct_htr, inputs=raw_htr_input, outputs=corrected_output)
|
51 |
+
|
52 |
+
with gr.Tab("Summarize Legal Text"):
|
53 |
+
gr.Markdown("### Summarize Legal Text")
|
54 |
+
legal_text_input = gr.Textbox(lines=10, placeholder="Enter legal text to summarize...")
|
55 |
+
summary_output = gr.Textbox(lines=5, placeholder="Summary of legal text")
|
56 |
+
summarize_button = gr.Button("Summarize Text")
|
57 |
+
summarize_button.click(summarize_text, inputs=legal_text_input, outputs=summary_output)
|
58 |
+
|
59 |
+
with gr.Tab("Answer Legal Question"):
|
60 |
+
gr.Markdown("### Answer a Question Based on Legal Text")
|
61 |
+
legal_text_input_q = gr.Textbox(lines=10, placeholder="Enter legal text...")
|
62 |
+
question_input = gr.Textbox(lines=2, placeholder="Enter your question...")
|
63 |
+
answer_output = gr.Textbox(lines=5, placeholder="Answer to your question")
|
64 |
+
answer_button = gr.Button("Get Answer")
|
65 |
+
answer_button.click(answer_question, inputs=[legal_text_input_q, question_input], outputs=answer_output)
|
66 |
+
|
67 |
+
demo.launch()
|
68 |
+
|