wop commited on
Commit
35041c8
1 Parent(s): 0c9d015

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +36 -0
main.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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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"}
13
+
14
+ def query2(payload):
15
+ response = requests.post(API_URL2, headers=headers2, json=payload)
16
+ return response.json()
17
+
18
+ def get_context(question):
19
+ payload = {"inputs": question}
20
+ result = query(payload)
21
+ return result['answer']
22
+
23
+ def ask_ai(question, context):
24
+ payload = {"question": question, "context": context}
25
+ result = query2(payload)
26
+ return result['answer']
27
+
28
+ iface = gr.Interface(
29
+ fn=ask_ai,
30
+ inputs=[gr.Textbox("Question", default=""), gr.Button("get_context", get_context)],
31
+ outputs=gr.Textbox("Answer"),
32
+ live=True,
33
+ capture_session=True,
34
+ )
35
+
36
+ iface.launch()