Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,33 +15,34 @@ 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 =
|
20 |
output = query({
|
21 |
"inputs": f"context for '{question}' is:",
|
22 |
})
|
23 |
-
|
24 |
|
25 |
-
def ask_question(
|
|
|
|
|
26 |
output2 = query2({
|
27 |
"inputs": {
|
28 |
"question": question,
|
29 |
"context": context
|
30 |
},
|
31 |
})
|
32 |
-
|
33 |
|
34 |
iface = gr.Interface(
|
35 |
fn=ask_question,
|
36 |
inputs=[
|
37 |
-
gr.Textbox("Enter your question", type="text", name="a"),
|
38 |
-
gr.Textbox("Enter context", type="text", name="b"),
|
39 |
gr.Button(detect_context_from_question, text="Detect Context", name="detect_button"),
|
40 |
gr.Button("Ask", name="ask_button")
|
41 |
],
|
42 |
-
outputs=gr.Textbox("
|
43 |
live=True
|
44 |
)
|
45 |
|
46 |
iface.launch()
|
47 |
-
|
|
|
15 |
response = requests.post(API_URL2, headers=headers2, json=payload)
|
16 |
return response.json()
|
17 |
|
18 |
+
def detect_context_from_question(inputs, outputs):
|
19 |
+
question = inputs["a"]
|
20 |
output = query({
|
21 |
"inputs": f"context for '{question}' is:",
|
22 |
})
|
23 |
+
inputs["b"].value = output # Update the value of the context Textbox
|
24 |
|
25 |
+
def ask_question(inputs, outputs):
|
26 |
+
question = inputs["a"]
|
27 |
+
context = inputs["b"]
|
28 |
output2 = query2({
|
29 |
"inputs": {
|
30 |
"question": question,
|
31 |
"context": context
|
32 |
},
|
33 |
})
|
34 |
+
outputs["answer"].value = output2 # Update the value of the answer Textbox
|
35 |
|
36 |
iface = gr.Interface(
|
37 |
fn=ask_question,
|
38 |
inputs=[
|
39 |
+
gr.Textbox("Enter your question", type="text", placeholder="Enter your question", name="a"),
|
40 |
+
gr.Textbox("Enter context", type="text", placeholder="Enter context", name="b"),
|
41 |
gr.Button(detect_context_from_question, text="Detect Context", name="detect_button"),
|
42 |
gr.Button("Ask", name="ask_button")
|
43 |
],
|
44 |
+
outputs=gr.Textbox("Answer", type="text", placeholder="Answer", name="answer"), # Single Textbox for the answer
|
45 |
live=True
|
46 |
)
|
47 |
|
48 |
iface.launch()
|
|