Spaces:
Runtime error
Runtime error
File size: 2,040 Bytes
f782c07 61febee f782c07 61febee d2a5637 6612259 d2a5637 61febee d2a5637 61febee d2a5637 1619dde 6612259 d2a5637 61febee d2a5637 61febee d2a5637 e9f62b3 d2a5637 61febee d2a5637 fc3da96 2613527 2f2bff4 2613527 2f2bff4 2613527 d2a5637 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import gradio as gr
import requests
API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
headers = {"Authorization": "Bearer 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"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
API_URL2 = "https://api-inference.huggingface.co/models/valhalla/longformer-base-4096-finetuned-squadv1"
headers2 = {"Authorization": "Bearer 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"}
def query2(payload):
response = requests.post(API_URL2, headers=headers2, json=payload)
return response.json()
class State:
question = ""
context = ""
answer = ""
state = State()
def detect_context_from_question():
state.question = detect_context_from_question.interface.inputs[0].value
output = query({
"inputs": f"context for '{state.question}' is:",
})
detect_context_from_question.interface.inputs[1].value = output # Update the value of the context Textbox
def ask_question():
state.question = ask_question.interface.inputs[0].value
state.context = ask_question.interface.inputs[1].value
output2 = query2({
"inputs": {
"question": state.question,
"context": state.context
},
})
ask_question.interface.outputs[0].value = output2 # Update the value of the answer Textbox
iface_detect = gr.Interface(
fn=detect_context_from_question,
inputs=[
gr.Textbox(type="text", placeholder="Enter your question"),
gr.Textbox(type="text", placeholder="Enter context"),
gr.Button("Detect Context")
],
outputs=None,
live=True
)
iface_ask = gr.Interface(
fn=ask_question,
inputs=[
gr.Textbox(type="text", placeholder="Enter your question"),
gr.Textbox(type="text", placeholder="Enter context"),
gr.Button("Ask")
],
outputs=gr.Textbox(type="text", placeholder="Answer"), # Single Textbox for the answer
live=True
)
iface_detect.launch()
iface_ask.launch()
|