khoatran94 commited on
Commit
f3423fc
1 Parent(s): 0d93a82
Files changed (2) hide show
  1. app.py +7 -13
  2. requirements.txt +1 -0
app.py CHANGED
@@ -20,6 +20,7 @@ from langchain.schema.runnable import RunnablePassthrough
20
  from langchain_core.messages import AIMessage, HumanMessage
21
  from langchain_community.llms import HuggingFaceEndpoint
22
  from dotenv import load_dotenv
 
23
 
24
  #zero = torch.Tensor([0]).cuda()
25
 
@@ -49,23 +50,16 @@ def read_pdf(file_path):
49
 
50
  # Function to query Hugging Face endpoint
51
  #@spaces.GPU
52
- # def query_huggingface(text):
53
- # print(zero.device)
54
- # tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
55
- # model = AutoModelForCausalLM.from_pretrained(
56
- # "google/gemma-2-9b-it",
57
- # device_map="auto",
58
- # torch_dtype=torch.bfloat16,
59
- # )
60
- # input_ids = tokenizer(text, return_tensors="pt").to("cuda")
61
- # outputs = model.generate(**input_ids, max_new_tokens=32)
62
- # return tokenizer.decode(outputs[0])
63
 
64
  # Gradio Interface for PDF Processing
65
  def process_file(file, query):
66
  pdf_output = read_pdf(file.name)
67
- #huggingface_output = query_huggingface(query)
68
- return pdf_output#, huggingface_output
69
 
70
  # Create Gradio App
71
  interface = gr.Interface(
 
20
  from langchain_core.messages import AIMessage, HumanMessage
21
  from langchain_community.llms import HuggingFaceEndpoint
22
  from dotenv import load_dotenv
23
+ from huggingface_hub import InferenceApi
24
 
25
  #zero = torch.Tensor([0]).cuda()
26
 
 
50
 
51
  # Function to query Hugging Face endpoint
52
  #@spaces.GPU
53
+ def query_huggingface(text):
54
+ api = InferenceApi(repo_id="google/gemma-2-9b-it", token="your_token_here")
55
+ response = api(inputs="Lê Duẩn là ai?")
56
+ return response
 
 
 
 
 
 
 
57
 
58
  # Gradio Interface for PDF Processing
59
  def process_file(file, query):
60
  pdf_output = read_pdf(file.name)
61
+ huggingface_output = query_huggingface(query)
62
+ return pdf_output, huggingface_output
63
 
64
  # Create Gradio App
65
  interface = gr.Interface(
requirements.txt CHANGED
@@ -17,3 +17,4 @@ sentence-transformers
17
  faiss-cpu
18
  bs4
19
  accelerate
 
 
17
  faiss-cpu
18
  bs4
19
  accelerate
20
+ huggingface_hub