Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,27 +2,7 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
import threading
|
4 |
|
5 |
-
# Number of backend servers (simulated instances of the pipeline)
|
6 |
-
NUM_BACKEND_SERVERS = 3
|
7 |
|
8 |
-
# Initialize backend servers (pipelines) and availability flags
|
9 |
-
backend_servers = [
|
10 |
-
pipeline("question-answering", model="google-bert/bert-large-uncased-whole-word-masking-finetuned-squad"),
|
11 |
-
pipeline("question-answering", model="deepset/roberta-base-squad2"),
|
12 |
-
pipeline("question-answering", model="Intel/dynamic_tinybert")
|
13 |
-
] * (NUM_BACKEND_SERVERS // 3)
|
14 |
-
backend_locks = [threading.Lock() for _ in range(NUM_BACKEND_SERVERS)]
|
15 |
-
|
16 |
-
# Function to select a backend server (pipeline) based on availability
|
17 |
-
def select_backend():
|
18 |
-
for i in range(NUM_BACKEND_SERVERS):
|
19 |
-
if backend_locks[i].acquire(blocking=False):
|
20 |
-
return i
|
21 |
-
return None
|
22 |
-
|
23 |
-
# Function to release a backend server (pipeline) after processing a request
|
24 |
-
def release_backend(index):
|
25 |
-
backend_locks[index].release()
|
26 |
|
27 |
# Use a pipeline as a high-level helper
|
28 |
from transformers import pipeline
|
@@ -40,7 +20,6 @@ def chatbot_interface(Question):
|
|
40 |
return answer
|
41 |
|
42 |
knowledge_base_text = """
|
43 |
-
|
44 |
3D+ : ;
|
45 |
3GGT : The 3 Great Growth Things ;
|
46 |
4D : Four "D" model ;
|
|
|
2 |
from transformers import pipeline
|
3 |
import threading
|
4 |
|
|
|
|
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Use a pipeline as a high-level helper
|
8 |
from transformers import pipeline
|
|
|
20 |
return answer
|
21 |
|
22 |
knowledge_base_text = """
|
|
|
23 |
3D+ : ;
|
24 |
3GGT : The 3 Great Growth Things ;
|
25 |
4D : Four "D" model ;
|