Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,11 +15,12 @@ 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 |
output = query({
|
| 20 |
"inputs": f"context for '{question}' is:",
|
| 21 |
})
|
| 22 |
-
|
| 23 |
|
| 24 |
def ask_question(question, context):
|
| 25 |
output2 = query2({
|
|
@@ -33,12 +34,14 @@ def ask_question(question, context):
|
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=ask_question,
|
| 35 |
inputs=[
|
| 36 |
-
gr.Textbox("Enter your question", type="text"),
|
| 37 |
-
gr.Textbox("Enter context", type="text"),
|
| 38 |
-
gr.Button(detect_context_from_question)
|
|
|
|
| 39 |
],
|
| 40 |
-
outputs=gr.Textbox("Output", type="text"),
|
| 41 |
live=True
|
| 42 |
)
|
| 43 |
|
| 44 |
iface.launch()
|
|
|
|
|
|
| 15 |
response = requests.post(API_URL2, headers=headers2, json=payload)
|
| 16 |
return response.json()
|
| 17 |
|
| 18 |
+
def detect_context_from_question(question_textbox, context_textbox):
|
| 19 |
+
question = question_textbox.value
|
| 20 |
output = query({
|
| 21 |
"inputs": f"context for '{question}' is:",
|
| 22 |
})
|
| 23 |
+
context_textbox.value = output['context']
|
| 24 |
|
| 25 |
def ask_question(question, context):
|
| 26 |
output2 = query2({
|
|
|
|
| 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("Output", type="text", name="b"), # Show context in the same Textbox as input
|
| 43 |
live=True
|
| 44 |
)
|
| 45 |
|
| 46 |
iface.launch()
|
| 47 |
+
|