Update file_viewer_panel.py
Browse files- file_viewer_panel.py +13 -26
file_viewer_panel.py
CHANGED
|
@@ -11,14 +11,14 @@ def file_viewer_dashboard(nickname_input):
|
|
| 11 |
file_text_state = gr.State("")
|
| 12 |
chat_history = gr.State([])
|
| 13 |
|
| 14 |
-
chat_input = gr.Textbox(label="๐ Ask about the file")
|
| 15 |
chat_output = gr.Chatbot()
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
quiz_btn = gr.Button("๐ง Generate Quiz")
|
| 24 |
quiz_score = gr.Textbox(label="Your Score", interactive=False, visible=False)
|
|
@@ -36,27 +36,14 @@ def file_viewer_dashboard(nickname_input):
|
|
| 36 |
history.append((query, answer))
|
| 37 |
return history, ""
|
| 38 |
|
| 39 |
-
def
|
| 40 |
prompt = f"""
|
| 41 |
-
|
| 42 |
-
Reformat the following content to improve readability and make it easier to follow:
|
| 43 |
- Use simple language
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
-
|
| 47 |
-
|
| 48 |
-
Text:
|
| 49 |
-
{text}
|
| 50 |
-
"""
|
| 51 |
-
return call_llm(prompt)
|
| 52 |
-
|
| 53 |
-
def improve_readability(text):
|
| 54 |
-
prompt = f"""
|
| 55 |
-
Please rewrite the following content to improve readability:
|
| 56 |
-
- Increase spacing
|
| 57 |
-
- Use larger font and clearer structure (for display purposes)
|
| 58 |
-
- Break into shorter paragraphs or bullet points
|
| 59 |
-
- Keep the meaning intact
|
| 60 |
|
| 61 |
Text:
|
| 62 |
{text}
|
|
@@ -86,9 +73,9 @@ Text:
|
|
| 86 |
return gr.update(visible=False), [], gr.update(visible=True, value="Error generating quiz.")
|
| 87 |
|
| 88 |
file_upload.change(fn=load_and_preview, inputs=[file_upload], outputs=[preview, file_text_state])
|
|
|
|
| 89 |
chat_input.submit(fn=handle_chat, inputs=[chat_input, file_text_state, chat_history], outputs=[chat_output, chat_input])
|
| 90 |
-
|
| 91 |
-
btn_readability.click(fn=improve_readability, inputs=[file_text_state], outputs=[readable_box])
|
| 92 |
quiz_btn.click(fn=generate_quiz, inputs=[file_text_state], outputs=[quiz_box, quiz_box, quiz_score])
|
| 93 |
|
| 94 |
return file_panel
|
|
|
|
| 11 |
file_text_state = gr.State("")
|
| 12 |
chat_history = gr.State([])
|
| 13 |
|
|
|
|
| 14 |
chat_output = gr.Chatbot()
|
| 15 |
|
| 16 |
+
with gr.Row():
|
| 17 |
+
chat_input = gr.Textbox(placeholder="Ask about the file...", label=None, lines=1)
|
| 18 |
+
send_btn = gr.Button("๐ค", size="sm", elem_id="send-btn")
|
| 19 |
|
| 20 |
+
btn_simplify = gr.Button("๐งพ Simplify Content")
|
| 21 |
+
simplified_box = gr.Textbox(label="๐ Simplified File Version", lines=15, interactive=False)
|
| 22 |
|
| 23 |
quiz_btn = gr.Button("๐ง Generate Quiz")
|
| 24 |
quiz_score = gr.Textbox(label="Your Score", interactive=False, visible=False)
|
|
|
|
| 36 |
history.append((query, answer))
|
| 37 |
return history, ""
|
| 38 |
|
| 39 |
+
def simplify_content(text):
|
| 40 |
prompt = f"""
|
| 41 |
+
Reformat the following content to improve readability and clarity:
|
|
|
|
| 42 |
- Use simple language
|
| 43 |
+
- Shorter paragraphs
|
| 44 |
+
- Larger font layout (for display)
|
| 45 |
+
- Use clear sections or bullet points when needed
|
| 46 |
+
- Preserve all original meaning
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
Text:
|
| 49 |
{text}
|
|
|
|
| 73 |
return gr.update(visible=False), [], gr.update(visible=True, value="Error generating quiz.")
|
| 74 |
|
| 75 |
file_upload.change(fn=load_and_preview, inputs=[file_upload], outputs=[preview, file_text_state])
|
| 76 |
+
send_btn.click(fn=handle_chat, inputs=[chat_input, file_text_state, chat_history], outputs=[chat_output, chat_input])
|
| 77 |
chat_input.submit(fn=handle_chat, inputs=[chat_input, file_text_state, chat_history], outputs=[chat_output, chat_input])
|
| 78 |
+
btn_simplify.click(fn=simplify_content, inputs=[file_text_state], outputs=[simplified_box])
|
|
|
|
| 79 |
quiz_btn.click(fn=generate_quiz, inputs=[file_text_state], outputs=[quiz_box, quiz_box, quiz_score])
|
| 80 |
|
| 81 |
return file_panel
|