Spaces:
Build error
Build error
toaster61 commited on
Commit ·
d1343e4
1
Parent(s): 773e76d
if it will work this is last commit using quart
Browse filesi want to move to gradio, it can do queue, i dont wanna do db to make queue, its useless
Files changed (4)
- Dockerfile+4
- app.py+25-8
- requirements.txt+4-1
- system.prompt+1-1
13 unmodified lines14151617181913 unmodified linesRUN chmod -R 777 /appWORKDIR /app# Installing wget and downloading model.RUN apt install wget -yRUN wget -q -O model.bin https://huggingface.co/TheBloke/Llama-2-13B-chat-GGUF/resolve/main/llama-2-13b-chat.Q5_K_M.gguf13 unmodified lines1415161718192021222313 unmodified linesRUN chmod -R 777 /appWORKDIR /app# Making dir for translator model (facebook/m2m100_1.2B)RUN mkdir translatorRUN chmod -R 777 /translator# Installing wget and downloading model.RUN apt install wget -yRUN wget -q -O model.bin https://huggingface.co/TheBloke/Llama-2-13B-chat-GGUF/resolve/main/llama-2-13b-chat.Q5_K_M.gguf
123456789101112131415161718192021222324259 unmodified lines353637383940from quart import Quart, requestfrom llama_cpp import Llamaapp = Quart(__name__)llm = Llama(model_path="./model.bin")with open('system.prompt', 'r', encoding='utf-8') as f:prompt = f.read()@app.post("/request")async def echo():try:data = await request.get_json()maxTokens = data.get("max_tokens", 64)userPrompt = prompt + "\n\nUser: " + data['request'] + "\nAssistant: "except: return {"error": "Not enough data"}, 400try:output = llm(userPrompt, max_tokens=maxTokens, stop=["User:", "\n"], echo=False)return {"output": output["choices"][0]["text"]}except Exception as e:print(e)return {"error": "Server error"}, 500@app.get("/")async def get():9 unmodified linesYou can install Docker, build image and run it. I made <code>`run-docker.sh`</code> for ya. To stop container run <code>`docker ps`</code>, find name of container and run <code>`docker stop _dockerContainerName_`</code><br>Or you can once follow steps in Dockerfile and try it on your machine, not in Docker.<br><br><h1>Also now it can run with Gradio! Check the repo!</h1><br><script>document.write("URL of space: "+window.location.href);</script>'''12345678910111213141516171819202122232425262728293031323334353637383940414243449 unmodified lines54555657# Importing librariesfrom transformers import M2M100Tokenizer, M2M100ForConditionalGenerationfrom quart import Quart, requestfrom llama_cpp import Llama# Initing thingsapp = Quart(__name__) # Quart appllm = Llama(model_path="./model.bin") # LLaMa modeltokenizer = M2M100Tokenizer.from_pretrained( # tokenizer for translator"facebook/m2m100_1.2B", cache_dir="translator/")model = M2M100ForConditionalGeneration.from_pretrained( # translator model"facebook/m2m100_1.2B", cache_dir="translator/")model.eval()# Preparing things to worktokenizer.src_lang = "en"# Loading promptwith open('system.prompt', 'r', encoding='utf-8') as f:prompt = f.read()# Defining@app.post("/request")async def echo():try:data = await request.get_json()maxTokens = data.get("max_tokens", 64)if isinstance(data.get("system_prompt"), str):userPrompt = data.get("system_prompt") + "\n\nUser: " + data['request'] + "\nAssistant: "else:userPrompt = prompt + "\n\nUser: " + data['request'] + "\nAssistant: "except:return {"error": "Not enough data", "output": "Oops! Error occured! If you're a developer, using this API, check 'error' key."}, 400try:output = llm(userPrompt, max_tokens=maxTokens, stop=["User:", "\n"], echo=False)return {"output": output["choices"][0]["text"]}except Exception as e:print(e)return {"error": str(e), "output": "Oops! Internal server error. Check the logs. If you're a developer, using this API, check 'error' key."}, 500@app.get("/")async def get():9 unmodified linesYou can install Docker, build image and run it. I made <code>`run-docker.sh`</code> for ya. To stop container run <code>`docker ps`</code>, find name of container and run <code>`docker stop _dockerContainerName_`</code><br>Or you can once follow steps in Dockerfile and try it on your machine, not in Docker.<br><br><script>document.write("<b>URL of space:</b> "+window.location.href);</script>'''
123Werkzeug==2.3.7quartuvicorn123456Werkzeug==2.3.7quartuvicorntorchtransformerstransformers[sentencepiece]
1234You're an AI assistant named Alisa. You're friendly and respectful.You speak as briefly, clearly and to the point as possible.You know many languages, for example: Russian, English.You don't have access to the internet, so rely on your knowledge.1234You're an AI assistant named Alex. You're friendly and respectful.You speak as briefly, clearly and to the point as possible.You know many languages, for example: Russian, English.You don't have access to the internet, so rely on your knowledge.
Dockerfile+4
app.py+25-8
requirements.txt+4-1
system.prompt+1-1