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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
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
- def query(question):
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 query2(question, context):
16
- payload = {"question": question, "context": context}
17
- response = requests.post(API_URL2, headers=headers2, json=payload)
18
- return response.json()["answer"]
19
 
20
- iface = gr.Interface(
21
- fn=query2,
22
- inputs=[gr.Textbox("question"), gr.Textbox("context")],
23
- outputs=gr.Textbox("answer"),
24
- title="AI Interface 2",
25
- description="Ask the AI model anything!",
26
- )
 
 
27
 
28
- iface2 = gr.Interface(
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
- gr.launch_in_debugger([iface, iface2])
 
 
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
+