wop commited on
Commit
d2a5637
1 Parent(s): 6612259

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -15,35 +15,51 @@ def query2(payload):
15
  response = requests.post(API_URL2, headers=headers2, json=payload)
16
  return response.json()
17
 
 
 
 
 
 
 
 
18
  def detect_context_from_question():
19
- question = detect_context_from_question.inputs[0].value
20
  output = query({
21
- "inputs": f"context for '{question}' is:",
22
  })
23
- detect_context_from_question.inputs[1].value = output # Update the value of the context Textbox
24
 
25
  def ask_question():
26
- question = ask_question.inputs[0].value
27
- context = ask_question.inputs[1].value
28
  output2 = query2({
29
  "inputs": {
30
- "question": question,
31
- "context": context
32
  },
33
  })
34
- ask_question.outputs[0].value = output2 # Update the value of the answer Textbox
 
 
 
 
 
 
 
 
 
 
35
 
36
- iface = gr.Interface(
37
  fn=ask_question,
38
  inputs=[
39
  gr.Textbox(type="text", placeholder="Enter your question"),
40
  gr.Textbox(type="text", placeholder="Enter context"),
41
- gr.Button(detect_context_from_question),
42
  gr.Button("Ask")
43
  ],
44
  outputs=gr.Textbox(type="text", placeholder="Answer"), # Single Textbox for the answer
45
  live=True
46
  )
47
 
48
- iface.launch()
49
-
 
15
  response = requests.post(API_URL2, headers=headers2, json=payload)
16
  return response.json()
17
 
18
+ class State:
19
+ question = ""
20
+ context = ""
21
+ answer = ""
22
+
23
+ state = State()
24
+
25
  def detect_context_from_question():
26
+ state.question = detect_context_from_question.interface.inputs[0].value
27
  output = query({
28
+ "inputs": f"context for '{state.question}' is:",
29
  })
30
+ detect_context_from_question.interface.inputs[1].value = output # Update the value of the context Textbox
31
 
32
  def ask_question():
33
+ state.question = ask_question.interface.inputs[0].value
34
+ state.context = ask_question.interface.inputs[1].value
35
  output2 = query2({
36
  "inputs": {
37
+ "question": state.question,
38
+ "context": state.context
39
  },
40
  })
41
+ ask_question.interface.outputs[0].value = output2 # Update the value of the answer Textbox
42
+
43
+ iface_detect = gr.Interface(
44
+ fn=detect_context_from_question,
45
+ inputs=[
46
+ gr.Textbox(type="text", placeholder="Enter your question"),
47
+ gr.Textbox(type="text", placeholder="Enter context"),
48
+ gr.Button("Detect Context")
49
+ ],
50
+ live=True
51
+ )
52
 
53
+ iface_ask = gr.Interface(
54
  fn=ask_question,
55
  inputs=[
56
  gr.Textbox(type="text", placeholder="Enter your question"),
57
  gr.Textbox(type="text", placeholder="Enter context"),
 
58
  gr.Button("Ask")
59
  ],
60
  outputs=gr.Textbox(type="text", placeholder="Answer"), # Single Textbox for the answer
61
  live=True
62
  )
63
 
64
+ iface_detect.launch()
65
+ iface_ask.launch()