Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from huggingface_hub import InferenceClient
|
|
3 |
from pathlib import Path
|
4 |
from typing import List
|
5 |
from pdfplumber import open as open_pdf
|
6 |
-
from transformers import
|
7 |
|
8 |
"""
|
9 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
@@ -19,9 +19,9 @@ with open_pdf(pdf_path) as pdf:
|
|
19 |
chunk_size = 1000 # Adjust this value based on your needs
|
20 |
text_chunks: List[str] = [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
|
21 |
|
22 |
-
# Load the
|
23 |
-
model =
|
24 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
25 |
|
26 |
def respond(
|
27 |
message,
|
@@ -50,7 +50,7 @@ def respond(
|
|
50 |
# Encode the context and user's message
|
51 |
input_ids = tokenizer.encode(context + "\n\n" + message, return_tensors="pt")
|
52 |
|
53 |
-
# Generate the response using the
|
54 |
output = model.generate(
|
55 |
input_ids,
|
56 |
max_length=max_tokens,
|
|
|
3 |
from pathlib import Path
|
4 |
from typing import List
|
5 |
from pdfplumber import open as open_pdf
|
6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
7 |
|
8 |
"""
|
9 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
|
|
19 |
chunk_size = 1000 # Adjust this value based on your needs
|
20 |
text_chunks: List[str] = [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
|
21 |
|
22 |
+
# Load the AutoModelForCausalLM and tokenizer
|
23 |
+
model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-tpu-automotive")
|
24 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-tpu-automotive")
|
25 |
|
26 |
def respond(
|
27 |
message,
|
|
|
50 |
# Encode the context and user's message
|
51 |
input_ids = tokenizer.encode(context + "\n\n" + message, return_tensors="pt")
|
52 |
|
53 |
+
# Generate the response using the AutoModelForCausalLM
|
54 |
output = model.generate(
|
55 |
input_ids,
|
56 |
max_length=max_tokens,
|