lhoestq HF staff commited on
Commit
359ad8b
1 Parent(s): 2e6dda3

add get route

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -1,6 +1,12 @@
 
1
  from typing import Dict, Union
2
- from gliner import GLiNER
3
  import gradio as gr
 
 
 
 
 
4
 
5
  model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")
6
  model.eval()
@@ -140,9 +146,21 @@ demo = gr.Interface(
140
  ],
141
  outputs=[gr.JSON()],
142
  examples=examples,
 
143
  title="NER.tool",
144
  description="Named Entity Recognition using urchade/gliner_medium-v2.1",
145
  allow_flagging="never",
146
  )
147
- demo.queue(max_size=4)
148
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
  from typing import Dict, Union
3
+
4
  import gradio as gr
5
+ import requests
6
+ import uvicorn
7
+ from fastapi import FastAPI
8
+ from gliner import GLiNER
9
+
10
 
11
  model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")
12
  model.eval()
 
146
  ],
147
  outputs=[gr.JSON()],
148
  examples=examples,
149
+ cache_examples="lazy",
150
  title="NER.tool",
151
  description="Named Entity Recognition using urchade/gliner_medium-v2.1",
152
  allow_flagging="never",
153
  )
154
+
155
+ app = FastAPI()
156
+
157
+ @app.get("/my_predict")
158
+ def read_main(text: str = ""):
159
+ predict_response = requests.post('http://localhost:7860/call/predict', json={'data': [text, 'pokemon', 0.3, False]}).json()
160
+ if "event_id" not in predict_response:
161
+ return predict_response
162
+ return json.loads(requests.get(f'http://localhost:7860/call/predict/{predict_response["event_id"]}').text.split("data: ", 1)[-1])
163
+
164
+ if __name__ == "__main__":
165
+ app = gr.mount_gradio_app(app, demo, path="/")
166
+ uvicorn.run(app, host="0.0.0.0", port=7860)