Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from llmlingua import PromptCompressor
|
4 |
+
import os
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
# Initialize LLM Lingua
|
9 |
+
compressor = PromptCompressor()
|
10 |
+
|
11 |
+
class TextInput(BaseModel):
|
12 |
+
text: str
|
13 |
+
|
14 |
+
class CompressedOutput(BaseModel):
|
15 |
+
compressed_text: str
|
16 |
+
|
17 |
+
@app.post("/compress", response_model=CompressedOutput)
|
18 |
+
async def compress_text(input: TextInput):
|
19 |
+
try:
|
20 |
+
compressed = compressor.compress_prompt(input.text)
|
21 |
+
return CompressedOutput(compressed_text=compressed)
|
22 |
+
except Exception as e:
|
23 |
+
raise HTTPException(status_code=500, detail=str(e))
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
import uvicorn
|
27 |
+
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|