Spaces:
Sleeping
Sleeping
Commit
·
b2a9bc3
1
Parent(s):
725770a
test
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import torch
|
|
7 |
import gradio as gr
|
8 |
from prepare import prepare
|
9 |
|
10 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
11 |
from langchain_community.llms import HuggingFacePipeline
|
12 |
from langchain.prompts import PromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate
|
13 |
from langchain_core.output_parsers import StrOutputParser
|
@@ -51,17 +51,15 @@ def read_pdf(file_path):
|
|
51 |
@spaces.GPU
|
52 |
def query_huggingface(text):
|
53 |
print(zero.device)
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
)
|
60 |
-
|
61 |
-
|
62 |
-
]
|
63 |
-
outputs = pipe(messages, max_new_tokens=256)
|
64 |
-
return outputs[0]["generated_text"][-1]["content"].strip()
|
65 |
|
66 |
# Gradio Interface for PDF Processing
|
67 |
def process_file(file, query):
|
|
|
7 |
import gradio as gr
|
8 |
from prepare import prepare
|
9 |
|
10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
11 |
from langchain_community.llms import HuggingFacePipeline
|
12 |
from langchain.prompts import PromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate
|
13 |
from langchain_core.output_parsers import StrOutputParser
|
|
|
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):
|