Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
-
import
|
2 |
-
import requests
|
3 |
|
4 |
-
|
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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"}
|
@@ -15,45 +9,20 @@ def query2(payload):
|
|
15 |
response = requests.post(API_URL2, headers=headers2, json=payload)
|
16 |
return response.json()
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
live=False # Set live to False
|
36 |
-
)
|
37 |
-
|
38 |
-
# Define the JavaScript function
|
39 |
-
javascript_code = """
|
40 |
-
function update_output() {
|
41 |
-
var question = gr("#text-input-0").val();
|
42 |
-
var context = gr("#text-input-1").val();
|
43 |
-
|
44 |
-
// Call the backend function with the updated values
|
45 |
-
gr('iframe').contentWindow.postMessage({
|
46 |
-
'task': 'updateOutput',
|
47 |
-
'data': {
|
48 |
-
'question': question,
|
49 |
-
'context': context
|
50 |
-
}
|
51 |
-
}, '*');
|
52 |
-
}
|
53 |
-
"""
|
54 |
-
|
55 |
-
# Attach the JavaScript code to the interface
|
56 |
-
iface_ask.inferface.html("head", f"<script>{javascript_code}</script>")
|
57 |
-
|
58 |
-
iface_ask.launch()
|
59 |
-
|
|
|
1 |
+
from flask import Flask, render_template, request
|
|
|
2 |
|
3 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
API_URL2 = "https://api-inference.huggingface.co/models/valhalla/longformer-base-4096-finetuned-squadv1"
|
6 |
headers2 = {"Authorization": "Bearer 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"}
|
|
|
9 |
response = requests.post(API_URL2, headers=headers2, json=payload)
|
10 |
return response.json()
|
11 |
|
12 |
+
@app.route("/", methods=["GET", "POST"])
|
13 |
+
def home():
|
14 |
+
answer = ""
|
15 |
+
if request.method == "POST":
|
16 |
+
question = request.form["question"]
|
17 |
+
context = request.form["context"]
|
18 |
+
output2 = query2({
|
19 |
+
"inputs": {
|
20 |
+
"question": question,
|
21 |
+
"context": context
|
22 |
+
},
|
23 |
+
})
|
24 |
+
answer = output2["answer"]
|
25 |
+
return render_template("index.html", answer=answer)
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|