Spaces:
Runtime error
Runtime error
Yash Sachdeva
commited on
Commit
·
dcd2d54
1
Parent(s):
e36eb52
question_paper
Browse files- Dockerfile +1 -1
- question_paper.py +34 -0
Dockerfile
CHANGED
@@ -5,5 +5,5 @@ RUN apt-get update && apt-get -y install libpq-dev gcc && pip install psycopg2
|
|
5 |
RUN pip install uvicorn
|
6 |
RUN pip install -r requirements.txt
|
7 |
COPY . /app
|
8 |
-
ENTRYPOINT [“uvicorn”,
|
9 |
CMD [“ — host”, “0.0.0.0”, “ — port”, “7860”]
|
|
|
5 |
RUN pip install uvicorn
|
6 |
RUN pip install -r requirements.txt
|
7 |
COPY . /app
|
8 |
+
ENTRYPOINT [“uvicorn”, question_paper:app”]
|
9 |
CMD [“ — host”, “0.0.0.0”, “ — port”, “7860”]
|
question_paper.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import copy
|
3 |
+
import asyncio
|
4 |
+
import requests
|
5 |
+
|
6 |
+
from fastapi import FastAPI, Request
|
7 |
+
from llama_cpp import Llama
|
8 |
+
from sse_starlette import EventSourceResponse
|
9 |
+
# Load the model
|
10 |
+
print("Loading model...")
|
11 |
+
llm = Llama(model_path="./llama-2-13b-chat.ggmlv3.q4_1.bin") # change based on the location of models
|
12 |
+
print("Model loaded!")
|
13 |
+
|
14 |
+
app = FastAPI()
|
15 |
+
|
16 |
+
@app.get("/llama")
|
17 |
+
async def llama(request: Request, question:str):
|
18 |
+
stream = llm(
|
19 |
+
f"""{question}""",
|
20 |
+
max_tokens=100,
|
21 |
+
stop=["\n", " Q:"],
|
22 |
+
stream=True,
|
23 |
+
)
|
24 |
+
async def async_generator():
|
25 |
+
for item in stream:
|
26 |
+
yield item
|
27 |
+
async def server_sent_events():
|
28 |
+
async for item in async_generator():
|
29 |
+
if await request.is_disconnected():
|
30 |
+
break
|
31 |
+
result = copy.deepcopy(item)
|
32 |
+
text = result["choices"][0]["text"]
|
33 |
+
yield {"data": text}
|
34 |
+
return EventSourceResponse(server_sent_events())
|