Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import time, aiohttp, asyncio, json, os, multiprocessing, torch
|
| 2 |
from minivectordb.embedding_model import EmbeddingModel
|
| 3 |
from minivectordb.vector_database import VectorDatabase
|
| 4 |
from text_util_en_pt.cleaner import structurize_text, detect_language, Language
|
|
@@ -12,10 +12,18 @@ import gradio as gr
|
|
| 12 |
torch.set_num_threads(2)
|
| 13 |
|
| 14 |
model = EmbeddingModel(use_quantized_onnx_model=True)
|
| 15 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 16 |
-
llm = AutoModelForCausalLM.from_pretrained("
|
| 17 |
|
| 18 |
-
prompt_template = "<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def fetch_links(query, max_results=5):
|
| 21 |
with DDGS() as ddgs:
|
|
@@ -59,7 +67,6 @@ def retrieval_pipeline(query):
|
|
| 59 |
|
| 60 |
return context, websearch_time, webcrawl_time, embedding_time, retrieval_time, links
|
| 61 |
|
| 62 |
-
@spaces.GPU(enable_queue=True)
|
| 63 |
def ask_open_llm(prompt):
|
| 64 |
device = torch.device('cuda')
|
| 65 |
|
|
@@ -73,7 +80,7 @@ def ask_open_llm(prompt):
|
|
| 73 |
generate_kwargs = dict(
|
| 74 |
model_inputs,
|
| 75 |
streamer=streamer,
|
| 76 |
-
max_new_tokens=
|
| 77 |
top_p=0.2,
|
| 78 |
top_k=20,
|
| 79 |
temperature=0.4,
|
|
|
|
| 1 |
+
import time, aiohttp, asyncio, json, os, multiprocessing, torch
|
| 2 |
from minivectordb.embedding_model import EmbeddingModel
|
| 3 |
from minivectordb.vector_database import VectorDatabase
|
| 4 |
from text_util_en_pt.cleaner import structurize_text, detect_language, Language
|
|
|
|
| 12 |
torch.set_num_threads(2)
|
| 13 |
|
| 14 |
model = EmbeddingModel(use_quantized_onnx_model=True)
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained("sreeramajay/TinyLlama-1.1B-orca-v1.0")
|
| 16 |
+
llm = AutoModelForCausalLM.from_pretrained("sreeramajay/TinyLlama-1.1B-orca-v1.0")
|
| 17 |
|
| 18 |
+
prompt_template = """<|system|>
|
| 19 |
+
You are a helpful assistant chatbot.</s>
|
| 20 |
+
<|user|>
|
| 21 |
+
$PROMPT</s>
|
| 22 |
+
<|assistant|>
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def count_tokens(text):
|
| 26 |
+
return len(tokenizer.encode(text))
|
| 27 |
|
| 28 |
def fetch_links(query, max_results=5):
|
| 29 |
with DDGS() as ddgs:
|
|
|
|
| 67 |
|
| 68 |
return context, websearch_time, webcrawl_time, embedding_time, retrieval_time, links
|
| 69 |
|
|
|
|
| 70 |
def ask_open_llm(prompt):
|
| 71 |
device = torch.device('cuda')
|
| 72 |
|
|
|
|
| 80 |
generate_kwargs = dict(
|
| 81 |
model_inputs,
|
| 82 |
streamer=streamer,
|
| 83 |
+
max_new_tokens=2048 - count_tokens(prompt),
|
| 84 |
top_p=0.2,
|
| 85 |
top_k=20,
|
| 86 |
temperature=0.4,
|