ai-920932093 / app.py
wop's picture
Update app.py
d1d7e61
raw
history blame
No virus
1.28 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()
def get_context_func(question, context_output):
payload = {"question": question}
result = query(payload)
context_output.update(result['answer'])
def ask_ai(question, context_output, answer_output):
payload = {"question": question, "context": context_output.value}
result = query2(payload)
answer_output.update(result['answer'])
iface = gr.Interface(
fn=ask_ai,
inputs=[
gr.Textbox("Question"),
gr.Textbox("Context"),
gr.Button("get_context", get_context_func),
gr.Button("ask_ai")
],
outputs=[
gr.Textbox("answer_output"),
gr.Textbox("context_output"),
]
)
iface.launch()