wop commited on
Commit
506adad
1 Parent(s): 698e18b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -22,18 +22,38 @@ def ask_question(question, context):
22
  "context": context
23
  },
24
  })
25
- ask_question.interface.outputs[0].value = output2 # Update the value of the answer Textbox
26
 
27
  iface_ask = gr.Interface(
28
  fn=ask_question,
29
  inputs=[
30
  gr.Textbox(type="text", placeholder="Enter your question"),
31
  gr.Textbox(type="text", placeholder="Enter context"),
32
- gr.Button("Ask")
33
  ],
34
  outputs=gr.Textbox(type="text", placeholder="Answer"), # Single Textbox for the answer
35
- live=True
36
  )
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  iface_ask.launch()
39
-
 
22
  "context": context
23
  },
24
  })
25
+ return output2
26
 
27
  iface_ask = gr.Interface(
28
  fn=ask_question,
29
  inputs=[
30
  gr.Textbox(type="text", placeholder="Enter your question"),
31
  gr.Textbox(type="text", placeholder="Enter context"),
32
+ gr.Button("Ask", onclick="update_output()") # Use custom JavaScript function
33
  ],
34
  outputs=gr.Textbox(type="text", placeholder="Answer"), # Single Textbox for the answer
35
+ live=False # Set live to False
36
  )
37
 
38
+ # Define the JavaScript function
39
+ javascript_code = """
40
+ function update_output() {
41
+ var question = gr("#text-input-0").val();
42
+ var context = gr("#text-input-1").val();
43
+
44
+ // Call the backend function with the updated values
45
+ gr('iframe').contentWindow.postMessage({
46
+ 'task': 'updateOutput',
47
+ 'data': {
48
+ 'question': question,
49
+ 'context': context
50
+ }
51
+ }, '*');
52
+ }
53
+ """
54
+
55
+ # Attach the JavaScript code to the interface
56
+ iface_ask.inferface.html("head", f"<script>{javascript_code}</script>")
57
+
58
  iface_ask.launch()
59
+