Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Define the function to answer questions
|
8 |
def get_answer(text):
|
9 |
-
|
|
|
10 |
return result["answer"]
|
11 |
|
12 |
# Define the Gradio interface
|
@@ -51,3 +61,6 @@ iface = gr.Interface(
|
|
51 |
)
|
52 |
|
53 |
iface.launch()
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import random
|
4 |
|
5 |
+
# List of backend servers (simulated instances of the pipeline)
|
6 |
+
backend_servers = [
|
7 |
+
pipeline("question-answering", model="google-bert/bert-large-uncased-whole-word-masking-finetuned-squad"),
|
8 |
+
pipeline("question-answering", model="google-bert/bert-large-uncased-whole-word-masking-finetuned-squad"),
|
9 |
+
pipeline("question-answering", model="google-bert/bert-large-uncased-whole-word-masking-finetuned-squad")
|
10 |
+
]
|
11 |
+
|
12 |
+
# Function to select a backend server in a round-robin manner
|
13 |
+
def select_backend():
|
14 |
+
return random.choice(backend_servers)
|
15 |
|
16 |
# Define the function to answer questions
|
17 |
def get_answer(text):
|
18 |
+
backend = select_backend()
|
19 |
+
result = backend(question=text, context=knowledge_base_text)
|
20 |
return result["answer"]
|
21 |
|
22 |
# Define the Gradio interface
|
|
|
61 |
)
|
62 |
|
63 |
iface.launch()
|
64 |
+
|
65 |
+
|
66 |
+
|