Spaces:
Sleeping
Sleeping
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from wrapper import LLMWrapper
|
2 |
+
import uvicorn
|
3 |
+
from fastapi import FastAPI, Request
|
4 |
+
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
llm_wrapper = LLMWrapper()
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
@app.post("/")
|
12 |
+
async def generate_text(request: Request):
|
13 |
+
raw_data = await request.body() # Get the raw body data from the request
|
14 |
+
prompt = raw_data.decode('utf-8')
|
15 |
+
if not prompt:
|
16 |
+
return {'error': 'Prompt is required'}, 400
|
17 |
+
|
18 |
+
generated_text = llm_wrapper.generate_text(prompt)
|
19 |
+
return {'generated_text': generated_text}
|
20 |
+
|
21 |
+
|
22 |
+
if __name__ == '__main__':
|
23 |
+
uvicorn.run(app, host='127.0.0.1', port=8001)
|