Spaces:
Sleeping
Sleeping
Commit
·
6858abc
1
Parent(s):
5e67c6e
test
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ from dotenv import load_dotenv
|
|
23 |
|
24 |
zero = torch.Tensor([0]).cuda()
|
25 |
|
26 |
-
|
27 |
def read_pdf(file_path):
|
28 |
output = ''
|
29 |
doc = pymupdf.open(file_path)
|
@@ -49,34 +49,34 @@ def read_pdf(file_path):
|
|
49 |
|
50 |
# Function to query Hugging Face endpoint
|
51 |
#@spaces.GPU
|
52 |
-
def query_huggingface(text):
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
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
|
69 |
|
70 |
# Create Gradio App
|
71 |
interface = gr.Interface(
|
72 |
fn=process_file,
|
73 |
inputs=[
|
74 |
gr.File(label="Upload a PDF file"),
|
75 |
-
gr.Textbox(label="Enter your query for Hugging Face"),
|
76 |
],
|
77 |
outputs=[
|
78 |
gr.Textbox(label="PDF Content"),
|
79 |
-
|
80 |
],
|
81 |
title="PDF Processor with Hugging Face Query"
|
82 |
)
|
|
|
23 |
|
24 |
zero = torch.Tensor([0]).cuda()
|
25 |
|
26 |
+
@spaces.GPU
|
27 |
def read_pdf(file_path):
|
28 |
output = ''
|
29 |
doc = pymupdf.open(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(
|
72 |
fn=process_file,
|
73 |
inputs=[
|
74 |
gr.File(label="Upload a PDF file"),
|
75 |
+
#gr.Textbox(label="Enter your query for Hugging Face"),
|
76 |
],
|
77 |
outputs=[
|
78 |
gr.Textbox(label="PDF Content"),
|
79 |
+
#gr.Textbox(label="Hugging Face Output"),
|
80 |
],
|
81 |
title="PDF Processor with Hugging Face Query"
|
82 |
)
|