Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# === Simple echo bot logic ===
|
| 4 |
+
def chat_response(history, message):
|
| 5 |
+
response = f"You said: {message}"
|
| 6 |
+
history = history + [(message, response)]
|
| 7 |
+
return history, ""
|
| 8 |
+
|
| 9 |
+
# === HTML + JS to inject Quill ===
|
| 10 |
+
quill_html = """
|
| 11 |
+
<div id="editor-container" style="height: 150px; border: 1px solid #ccc;"></div>
|
| 12 |
+
<button onclick="submitQuill()" style="margin-top:10px;">Send</button>
|
| 13 |
+
|
| 14 |
+
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
|
| 15 |
+
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
|
| 16 |
+
|
| 17 |
+
<script>
|
| 18 |
+
let quill = new Quill('#editor-container', {
|
| 19 |
+
theme: 'snow'
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
function submitQuill() {
|
| 23 |
+
const text = quill.root.innerHTML;
|
| 24 |
+
document.querySelector('textarea[data-testid="quill_input"]').value = text;
|
| 25 |
+
document.querySelector('button[data-testid="quill_hidden_submit"]').click();
|
| 26 |
+
}
|
| 27 |
+
</script>
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
# === Gradio Interface ===
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
chatbot = gr.Chatbot()
|
| 33 |
+
with gr.Row():
|
| 34 |
+
gr.HTML(quill_html)
|
| 35 |
+
# Hidden components to pass data from JS
|
| 36 |
+
msg = gr.Textbox(visible=False, elem_id="quill_input")
|
| 37 |
+
submit_btn = gr.Button("Submit Hidden", visible=False, elem_id="quill_hidden_submit")
|
| 38 |
+
state = gr.State([])
|
| 39 |
+
|
| 40 |
+
submit_btn.click(chat_response, inputs=[state, msg], outputs=[chatbot, msg], show_progress=False).then(
|
| 41 |
+
lambda h: h, inputs=chatbot, outputs=state
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
demo.launch(share=True, debug=True)
|