Update file_viewer_panel.py
Browse files- file_viewer_panel.py +15 -10
file_viewer_panel.py
CHANGED
|
@@ -5,19 +5,25 @@ from file_utils import extract_text_from_file, call_llm
|
|
| 5 |
|
| 6 |
def file_viewer_dashboard(nickname_input):
|
| 7 |
with gr.Column(scale=4, elem_id="main-column") as file_panel:
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
|
|
|
| 11 |
file_text_state = gr.State("")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
quiz_box = gr.Column(visible=False)
|
| 20 |
-
quiz_score = gr.Textbox(label="Your Score", interactive=False, visible=False)
|
| 21 |
|
| 22 |
def load_and_preview(file):
|
| 23 |
if not file:
|
|
@@ -32,7 +38,6 @@ def file_viewer_dashboard(nickname_input):
|
|
| 32 |
def make_accessible_version(text):
|
| 33 |
prompt = f"""
|
| 34 |
You are an expert in reading accessibility.
|
| 35 |
-
|
| 36 |
Reformat the following content to improve readability and make it easier to follow:
|
| 37 |
- Use simple language
|
| 38 |
- Break long paragraphs
|
|
@@ -69,6 +74,6 @@ Text:
|
|
| 69 |
file_upload.change(fn=load_and_preview, inputs=[file_upload], outputs=[preview, file_text_state])
|
| 70 |
chat_input.submit(fn=handle_chat, inputs=[chat_input, file_text_state], outputs=[chat_output])
|
| 71 |
btn_accessible.click(fn=make_accessible_version, inputs=[file_text_state], outputs=[accessible_box])
|
| 72 |
-
|
| 73 |
|
| 74 |
-
return file_panel
|
|
|
|
| 5 |
|
| 6 |
def file_viewer_dashboard(nickname_input):
|
| 7 |
with gr.Column(scale=4, elem_id="main-column") as file_panel:
|
| 8 |
+
with gr.Row():
|
| 9 |
+
file_upload = gr.File(label="π Upload a File", file_types=[".pdf", ".txt", ".md", ".pptx"])
|
| 10 |
|
| 11 |
+
preview = gr.Textbox(label="π File Content Preview", lines=10, interactive=False)
|
| 12 |
file_text_state = gr.State("")
|
| 13 |
|
| 14 |
+
with gr.Row():
|
| 15 |
+
chat_input = gr.Textbox(label="π Ask about the file")
|
| 16 |
+
chat_output = gr.Chatbot()
|
| 17 |
|
| 18 |
+
with gr.Row():
|
| 19 |
+
btn_accessible = gr.Button("βΏοΈ Improve Accessibility")
|
| 20 |
+
accessible_box = gr.Textbox(label="π Easier-to-Read Version", lines=15, interactive=False)
|
| 21 |
+
|
| 22 |
+
with gr.Row():
|
| 23 |
+
quiz_btn = gr.Button("π§ Generate Quiz")
|
| 24 |
+
quiz_score = gr.Textbox(label="Your Score", interactive=False, visible=False)
|
| 25 |
|
| 26 |
quiz_box = gr.Column(visible=False)
|
|
|
|
| 27 |
|
| 28 |
def load_and_preview(file):
|
| 29 |
if not file:
|
|
|
|
| 38 |
def make_accessible_version(text):
|
| 39 |
prompt = f"""
|
| 40 |
You are an expert in reading accessibility.
|
|
|
|
| 41 |
Reformat the following content to improve readability and make it easier to follow:
|
| 42 |
- Use simple language
|
| 43 |
- Break long paragraphs
|
|
|
|
| 74 |
file_upload.change(fn=load_and_preview, inputs=[file_upload], outputs=[preview, file_text_state])
|
| 75 |
chat_input.submit(fn=handle_chat, inputs=[chat_input, file_text_state], outputs=[chat_output])
|
| 76 |
btn_accessible.click(fn=make_accessible_version, inputs=[file_text_state], outputs=[accessible_box])
|
| 77 |
+
quiz_btn.click(fn=generate_quiz, inputs=[file_text_state], outputs=[quiz_box, quiz_box, quiz_score])
|
| 78 |
|
| 79 |
+
return file_panel
|