wop commited on
Commit
af9ec9a
1 Parent(s): 8cc4952

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -27
app.py CHANGED
@@ -1,40 +1,25 @@
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
  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()
 
1
  import gradio as gr
2
  import requests
3
 
4
+
5
  API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
6
  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
+ def query(payload):
10
+ payload2 = "whats the context of teh question " + paylaod + " :"
11
+ response = requests.post(API_URL, headers=headers, json=payload2)
12
+ return response.json()["answer"]
13
+ def query2(payload):
14
+ response = requests.post(API_URL2, headers=headers2, json=payload)
15
+ return response.json()["answer"]
16
 
17
+ iface = gr.Interface(
18
+ fn=query2,
 
 
 
 
 
 
 
 
19
  inputs=[gr.Textbox("question"), gr.Textbox("context")],
20
  outputs=gr.Textbox("answer"),
21
+ title="AI Interface",
22
  description="Ask the AI model anything!",
23
  )
24
 
25
+ iface.launch()