Spaces:
Sleeping
Sleeping
oscarwang2
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -46,8 +46,8 @@ def process_queue():
|
|
46 |
label, score = classify_text(request['text'])
|
47 |
request['response'].append((label, score))
|
48 |
else:
|
49 |
-
# Put it back in the queue
|
50 |
-
|
51 |
time.sleep(0.1) # Adjust the sleep time as necessary
|
52 |
|
53 |
def queue_request(text, api_key):
|
@@ -68,6 +68,9 @@ def queue_request(text, api_key):
|
|
68 |
|
69 |
return response[0]
|
70 |
|
|
|
|
|
|
|
71 |
# Start the queue processing thread
|
72 |
threading.Thread(target=process_queue, daemon=True).start()
|
73 |
|
@@ -83,5 +86,15 @@ interface = gr.Interface(
|
|
83 |
description="A simple app to classify text using the roberta-mixed-detector model with priority queuing."
|
84 |
)
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
# Launch the app
|
87 |
-
|
|
|
46 |
label, score = classify_text(request['text'])
|
47 |
request['response'].append((label, score))
|
48 |
else:
|
49 |
+
# Put it back in the queue if there are authenticated requests
|
50 |
+
authenticated_queue.put(request)
|
51 |
time.sleep(0.1) # Adjust the sleep time as necessary
|
52 |
|
53 |
def queue_request(text, api_key):
|
|
|
68 |
|
69 |
return response[0]
|
70 |
|
71 |
+
def get_queue_sizes():
|
72 |
+
return len(authenticated_queue.queue), len(non_authenticated_queue.queue)
|
73 |
+
|
74 |
# Start the queue processing thread
|
75 |
threading.Thread(target=process_queue, daemon=True).start()
|
76 |
|
|
|
86 |
description="A simple app to classify text using the roberta-mixed-detector model with priority queuing."
|
87 |
)
|
88 |
|
89 |
+
queue_interface = gr.Interface(
|
90 |
+
fn=get_queue_sizes,
|
91 |
+
inputs=[],
|
92 |
+
outputs=[gr.Number(label="Authenticated Queue Size"), gr.Number(label="Non-Authenticated Queue Size")],
|
93 |
+
live=True
|
94 |
+
)
|
95 |
+
|
96 |
+
# Combine the interfaces
|
97 |
+
combined_interface = gr.TabbedInterface([interface, queue_interface], ["Classify Text", "Queue Sizes"])
|
98 |
+
|
99 |
# Launch the app
|
100 |
+
combined_interface.launch()
|