Spaces:
Sleeping
Sleeping
Update app.py
Browse files39 unmodified lines40414243444546474849505152535455565758596061626364656667686970717273747576777879808182434445464748495051525354555657585960616263646539 unmodified lines yield response
# HTML injection and JavaScript for passing the question dynamically to the chatbotdef create_interface(): with gr.Blocks() as demo: with gr.Row(): gr.HTML(""" <button id="ai-button" style="padding: 12px 24px; font-size: 16px; font-weight: bold; cursor: pointer; background-color: #007BFF; color: white; border: none; border-radius: 5px; margin: 15px 0;">Ask AI</button> <div id="ai-container" style="width: 100%; height: 600px; margin-top: 15px; display: none;"> <iframe id="chatbot-iframe" src="https://huggingface.co/spaces/your-chatbot-url" width="100%" height="100%" style="border: none;"></iframe> </div> <script> document.getElementById("ai-button").onclick = function() { var aiContainer = document.getElementById("ai-container"); if (aiContainer.style.display === "none") { aiContainer.style.display = "block"; // Show iframe sendQuestionToChatbot(); // Send the current question to the chatbot } else { aiContainer.style.display = "none"; // Hide iframe } };
function sendQuestionToChatbot() { // Get the text of the current question dynamically var questionText = "What is the capital of France?"; // Replace with dynamic question input from Qualtrics
// Send this question to the chatbot inside the iframe using postMessage document.getElementById("chatbot-iframe").contentWindow.postMessage({type: "send_question", text: questionText}, "*"); } </script> """) with gr.Column(): input_box = gr.Textbox(placeholder="Enter a question...", label="User Input") output = gr.Textbox(label="AI Response") input_box.submit(respond, inputs=input_box, outputs=output)
return demo
# Launch the Gradio appdemo = create_interface()demo.launch(server_name="0.0.0.0", server_port=7860)
"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface( respond, additional_inputs=[ gr.Textbox(value="You are a friendly Chatbot.", label="System message"), gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), gr.Slider( minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)", ), ],)
if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)
app.py+22-40