Moha782 commited on
Commit
397c221
·
verified ·
1 Parent(s): 71de07a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
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 GPT2LMHeadModel, 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,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 GPT2LMHeadModel and tokenizer
23
- model = GPT2LMHeadModel.from_pretrained("gpt2")
24
- tokenizer = AutoTokenizer.from_pretrained("gpt2")
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 GPT2LMHeadModel
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,