Spaces:
Build error
Build error
Commit ·
0877002
1
Parent(s): 35caa8b
Changes
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from typing import List, Union, Dict, Tuple
|
|
| 3 |
from transformers import pipeline
|
| 4 |
from os import getenv
|
| 5 |
from huggingface_hub import login
|
| 6 |
-
import pymupdf
|
| 7 |
|
| 8 |
from history import get_history, update_history
|
| 9 |
|
|
@@ -41,13 +41,14 @@ def extract_text_from_pdf(pdf_path):
|
|
| 41 |
|
| 42 |
|
| 43 |
#Does the actual inference and streams (yield) the response
|
| 44 |
-
def chat(history:list[dict[str, str]],temperature,top_p,max_tokens):
|
| 45 |
for msg in generator(
|
| 46 |
history, #message list
|
| 47 |
max_new_tokens=max_tokens,
|
| 48 |
return_full_text=False,
|
| 49 |
temperature=temperature,
|
| 50 |
top_p=top_p,
|
|
|
|
| 51 |
#max_tokens=max_tokens
|
| 52 |
):
|
| 53 |
yield msg['generated_text']
|
|
@@ -92,7 +93,13 @@ def respond(
|
|
| 92 |
mainMessage=[{"role": "system", "content": system_message}, *messages]
|
| 93 |
|
| 94 |
#calls the inference function and streams the response
|
| 95 |
-
for msg in chat(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
token = msg
|
| 97 |
|
| 98 |
# This is a stream. Meaning response comes in bits of string.
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
from os import getenv
|
| 5 |
from huggingface_hub import login
|
| 6 |
+
import pymupdf
|
| 7 |
|
| 8 |
from history import get_history, update_history
|
| 9 |
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
#Does the actual inference and streams (yield) the response
|
| 44 |
+
def chat(history:list[dict[str, str]],temperature,top_p,max_tokens,top_k):
|
| 45 |
for msg in generator(
|
| 46 |
history, #message list
|
| 47 |
max_new_tokens=max_tokens,
|
| 48 |
return_full_text=False,
|
| 49 |
temperature=temperature,
|
| 50 |
top_p=top_p,
|
| 51 |
+
top_k=top_k
|
| 52 |
#max_tokens=max_tokens
|
| 53 |
):
|
| 54 |
yield msg['generated_text']
|
|
|
|
| 93 |
mainMessage=[{"role": "system", "content": system_message}, *messages]
|
| 94 |
|
| 95 |
#calls the inference function and streams the response
|
| 96 |
+
for msg in chat(
|
| 97 |
+
mainMessage,
|
| 98 |
+
temperature=temperature,
|
| 99 |
+
top_p=top_p,
|
| 100 |
+
max_tokens=max_tokens,
|
| 101 |
+
top_k=12
|
| 102 |
+
):
|
| 103 |
token = msg
|
| 104 |
|
| 105 |
# This is a stream. Meaning response comes in bits of string.
|