File size: 1,004 Bytes
d92c861
 
 
 
 
4442b70
d92c861
 
 
a0778be
 
 
 
fabd34d
a0778be
d92c861
 
 
 
 
 
 
 
 
 
 
4442b70
 
a0778be
4442b70
 
a0778be
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.responses import StreamingResponse
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from io import StringIO
import os

from llmlingua import PromptCompressor
llm_lingua = PromptCompressor(
    model_name="microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank",
    use_llmlingua2=True, # Whether to use llmlingua-2
    device_map="cpu"
)


app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

class Prompt(BaseModel:
    original_prompt: str
@app.post("/get_compressed_text")
async def get_compressed_text(prompt: Prompt):
        compressed_prompt = llm_lingua.compress_prompt(prompt.original_propmt, instruction="", question="")
        print("compressed")
        return compressed_prompt