sarasad commited on
Commit
5d2daf9
·
1 Parent(s): 1144d20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -27,6 +27,44 @@ def chatbot(message):
27
  iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
28
 
29
  # Customize the layout to display the conversation
30
- iface.layout("textarea", "textbox")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  iface.launch()
 
27
  iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
28
 
29
  # Customize the layout to display the conversation
30
+ iface.interface_html = """
31
+ <div>
32
+ <div>
33
+ <textarea id="input_text" rows="4" cols="50" placeholder="User input"></textarea>
34
+ <button id="submit_button">Send</button>
35
+ </div>
36
+ <div id="conversation" style="margin-top: 10px;"></div>
37
+ </div>
38
+
39
+ <script>
40
+ // Function to update the conversation display
41
+ function updateConversation() {
42
+ var conversation = gradio.interfaceInstances[0].cache["conversation"];
43
+ var conversationDiv = document.getElementById("conversation");
44
+ conversationDiv.innerHTML = "";
45
+ for (var i = 0; i < conversation.length; i++) {
46
+ var message = conversation[i];
47
+ var messageDiv = document.createElement("div");
48
+ messageDiv.innerHTML = message;
49
+ conversationDiv.appendChild(messageDiv);
50
+ }
51
+ }
52
+
53
+ // Add event listener for the submit button
54
+ var submitButton = document.getElementById("submit_button");
55
+ submitButton.addEventListener("click", function() {
56
+ var inputText = document.getElementById("input_text").value;
57
+ if (inputText) {
58
+ gradio.interfaceInstances[0].input_interfaces[0].setValue(inputText);
59
+ gradio.interfaceInstances[0].submit();
60
+ }
61
+ });
62
+
63
+ // Update the conversation display on page load
64
+ window.onload = function() {
65
+ updateConversation();
66
+ }
67
+ </script>
68
+ """
69
 
70
  iface.launch()