Lamp Socrates
commited on
Commit
·
ea7e2bf
1
Parent(s):
e4e76c6
latest commit
Browse files- app.py +27 -3
- locustfile.py +28 -0
- stresstest_ner_service.ipynb +0 -0
app.py
CHANGED
@@ -107,6 +107,14 @@ def ner_demo(text):
|
|
107 |
return color_coded_text
|
108 |
|
109 |
PROJECT_INTRO = "This is a HF Spaces hosted Gradio App built by NLP Group 27 . The model has been trained on surrey-nlp/PLOD-CW dataset"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
# Create the Gradio interface
|
111 |
demo = gr.Interface(
|
112 |
fn=ner_demo,
|
@@ -116,6 +124,22 @@ demo = gr.Interface(
|
|
116 |
title="Named Entity Recognition on PLOD-CW ",
|
117 |
description=f"{PROJECT_INTRO}\n\nEnter text to extract named entities using a NER model."
|
118 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
# Function to run FastAPI
|
121 |
def run_fastapi():
|
@@ -125,7 +149,7 @@ def run_fastapi():
|
|
125 |
def run_gradio():
|
126 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
threading.Thread(target=run_gradio).start()
|
131 |
|
|
|
107 |
return color_coded_text
|
108 |
|
109 |
PROJECT_INTRO = "This is a HF Spaces hosted Gradio App built by NLP Group 27 . The model has been trained on surrey-nlp/PLOD-CW dataset"
|
110 |
+
|
111 |
+
def echo(text, request: gr.Request):
|
112 |
+
if request:
|
113 |
+
print("Request headers dictionary:", request.headers)
|
114 |
+
print("IP address:", request.client.host)
|
115 |
+
print("Query parameters:", dict(request.query_params))
|
116 |
+
return text
|
117 |
+
|
118 |
# Create the Gradio interface
|
119 |
demo = gr.Interface(
|
120 |
fn=ner_demo,
|
|
|
124 |
title="Named Entity Recognition on PLOD-CW ",
|
125 |
description=f"{PROJECT_INTRO}\n\nEnter text to extract named entities using a NER model."
|
126 |
)
|
127 |
+
'''
|
128 |
+
with gr.Blocks() as demo:
|
129 |
+
gr.Markdown("# Page Title")
|
130 |
+
gr.Markdown("## Subtitle with h2 Font")
|
131 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text")
|
132 |
+
|
133 |
+
with gr.Column():
|
134 |
+
echo_output = gr.Textbox(label="Echo Output")
|
135 |
+
html_output = ner_demo
|
136 |
+
|
137 |
+
with gr.Column():
|
138 |
+
button1 = gr.Button("Submit")
|
139 |
+
'''
|
140 |
+
|
141 |
+
CUSTOM_PATH = "/gradio"
|
142 |
+
app = gr.mount_gradio_app(app, demo, path=CUSTOM_PATH)
|
143 |
|
144 |
# Function to run FastAPI
|
145 |
def run_fastapi():
|
|
|
149 |
def run_gradio():
|
150 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
151 |
|
152 |
+
|
153 |
+
run_fastapi()
|
154 |
+
#threading.Thread(target=run_gradio).start()
|
155 |
|
locustfile.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from locust import HttpUser, task, between
|
2 |
+
from datasets import load_dataset
|
3 |
+
import random
|
4 |
+
datCW = load_dataset("surrey_nlp/PLOD_CW")
|
5 |
+
|
6 |
+
|
7 |
+
def pick_random_payload():
|
8 |
+
global datCW
|
9 |
+
idx = random.randint(0, len(datCW["test"])-1)
|
10 |
+
tokens = datCW["test"][idx]["tokens"]
|
11 |
+
payload = ' '.join(tokens)
|
12 |
+
print(payload)
|
13 |
+
return payload
|
14 |
+
|
15 |
+
class ApiUser(HttpUser):
|
16 |
+
wait_time = between(1, 5)
|
17 |
+
|
18 |
+
@task
|
19 |
+
def ner_endpoint(self):
|
20 |
+
payload = pick_random_payload()
|
21 |
+
payload = {
|
22 |
+
"text": payload
|
23 |
+
}
|
24 |
+
self.client.post("/ner", json=payload)
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
import os
|
28 |
+
os.system("locust -f locustfile.py")
|
stresstest_ner_service.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|