autocontext / app.py
wop's picture
Update app.py
a2f3824
raw
history blame
1.38 kB
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 ask_question(question, context):
state.question = question
state.context = context
output2 = query2({
"inputs": {
"question": state.question,
"context": state.context
},
})
ask_question.interface.outputs[0].value = output2 # Update the value of the answer Textbox
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_ask.launch()