wop commited on
Commit
3131453
1 Parent(s): 02326c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -20
app.py CHANGED
@@ -7,29 +7,34 @@ 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
- 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
 
 
 
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
+ model_1_interface = gr.Interface(
11
+ fn=lambda question, context="": query(question, context, API_URL, headers),
12
+ inputs=[gr.Textbox("question"), gr.Textbox("context")],
13
+ outputs=gr.Textbox("answer"),
14
+ title="Model 1 Interface",
15
+ description="Ask the AI model anything!",
16
+ )
 
 
 
 
 
 
 
 
17
 
18
+ model_2_interface = gr.Interface(
19
+ fn=lambda question, context="": query(question, context, API_URL2, headers2),
20
+ inputs=[gr.Textbox("question"), gr.Textbox("context")],
21
  outputs=gr.Textbox("answer"),
22
+ title="Model 2 Interface",
23
  description="Ask the AI model anything!",
24
  )
25
 
26
+ def query(question, context, api_url, headers):
27
+ if api_url = API_URL:
28
+ payload = {"question": question, "context": context}
29
+ else:
30
+ paylaod = {"question": "what is the context of the question: "+question+" :"}
31
+ response = requests.post(api_url, headers=headers, json=payload)
32
+ return response.json()["answer"]
33
+
34
+ def switch_model():
35
+ if gr.Interface.get_active() == model_1_interface:
36
+ model_2_interface.launch()
37
+ else:
38
+ model_1_interface.launch()
39
 
40
+ model_1_interface.launch()