Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,30 +7,29 @@ headers = {"Authorization": "Bearer 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"}
|
|
7 |
API_URL2 = "https://api-inference.huggingface.co/models/valhalla/longformer-base-4096-finetuned-squadv1"
|
8 |
headers2 = {"Authorization": "Bearer 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"}
|
9 |
|
10 |
-
|
11 |
-
payload = {"question": "what is the context of "+question+" : "}
|
12 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
13 |
-
return response.json()["answer"]
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
return response.json()["answer"]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
|
29 |
fn=query,
|
30 |
-
inputs=[gr.Textbox("question")],
|
31 |
outputs=gr.Textbox("answer"),
|
32 |
title="AI Interface",
|
33 |
description="Ask the AI model anything!",
|
34 |
)
|
35 |
|
36 |
-
|
|
|
|
7 |
API_URL2 = "https://api-inference.huggingface.co/models/valhalla/longformer-base-4096-finetuned-squadv1"
|
8 |
headers2 = {"Authorization": "Bearer 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"}
|
9 |
|
10 |
+
current_model = 1 # Default to the first model
|
|
|
|
|
|
|
11 |
|
12 |
+
def switch_model():
|
13 |
+
global current_model
|
14 |
+
current_model = 1 if current_model == 2 else 2
|
|
|
15 |
|
16 |
+
def query(question, context=""):
|
17 |
+
if current_model == 1:
|
18 |
+
payload = {"question": question, "context": context}
|
19 |
+
response = requests.post(API_URL2, headers=headers2, json=payload)
|
20 |
+
return response.json()["answer"]
|
21 |
+
else:
|
22 |
+
payload = {"question": "what is the context of the question: "+question+" :"}
|
23 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
24 |
+
return response.json()["answer"]
|
25 |
|
26 |
+
iface = gr.Interface(
|
27 |
fn=query,
|
28 |
+
inputs=[gr.Textbox("question"), gr.Textbox("context"), gr.Button("Switch Model", switch_model)],
|
29 |
outputs=gr.Textbox("answer"),
|
30 |
title="AI Interface",
|
31 |
description="Ask the AI model anything!",
|
32 |
)
|
33 |
|
34 |
+
iface.launch()
|
35 |
+
|