Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
| 5 |
+
headers = {"Authorization": "Bearer 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"}
|
| 6 |
+
|
| 7 |
+
def query(payload):
|
| 8 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 9 |
+
return response.json()
|
| 10 |
+
|
| 11 |
+
API_URL2 = "https://api-inference.huggingface.co/models/valhalla/longformer-base-4096-finetuned-squadv1"
|
| 12 |
+
headers2 = {"Authorization": "Bearer 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"}
|
| 13 |
+
|
| 14 |
+
def query2(payload):
|
| 15 |
+
response = requests.post(API_URL2, headers=headers2, json=payload)
|
| 16 |
+
return response.json()
|
| 17 |
+
|
| 18 |
+
def inference_ui(question):
|
| 19 |
+
output = query({
|
| 20 |
+
"inputs": f"context for '{question}' is:",
|
| 21 |
+
})
|
| 22 |
+
output2 = query2({
|
| 23 |
+
"inputs": {
|
| 24 |
+
"question": question,
|
| 25 |
+
"context": output
|
| 26 |
+
},
|
| 27 |
+
})
|
| 28 |
+
return output2
|
| 29 |
+
|
| 30 |
+
iface = gr.Interface(fn=inference_ui, inputs="text", outputs="text")
|
| 31 |
+
iface.launch()
|