Spaces:
Running
on
Zero
Running
on
Zero
Felipe Silva
commited on
Commit
·
ece1514
1
Parent(s):
d4a1668
Ajuste doc converter
Browse files
app.py
CHANGED
|
@@ -10,14 +10,9 @@ import config
|
|
| 10 |
zero = torch.Tensor([0]).cuda()
|
| 11 |
print(zero.device) # <-- 'cpu' 🤔
|
| 12 |
|
| 13 |
-
# @spaces.GPU
|
| 14 |
-
# def greet(n):
|
| 15 |
-
# print(zero.device) # <-- 'cuda:0' 🤗
|
| 16 |
-
# return f"Hello {zero + n} Tensor"
|
| 17 |
-
|
| 18 |
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
|
| 19 |
|
| 20 |
-
name_model = "Qwen/Qwen2.5-7B-Instruct-GPTQ-Int8"
|
| 21 |
config.local_model_path = snapshot_download(
|
| 22 |
repo_id=name_model,
|
| 23 |
cache_dir="/root/.cache/huggingface",
|
|
@@ -37,14 +32,11 @@ def process_file(file):
|
|
| 37 |
if file_size > MAX_FILE_SIZE:
|
| 38 |
return f"O arquivo excede o limite. Por favor, realize o upload de um arquivo que contenha no máximo {MAX_FILE_SIZE/1024/1024:.1f}MB."
|
| 39 |
|
| 40 |
-
|
| 41 |
-
texto_extraido
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
elif type_file in EXTENSIONS_IMG_FILES:
|
| 46 |
-
texto_extraido = doc_converter(file)
|
| 47 |
-
return texto_extraido or "Não foi possível extrair texto."
|
| 48 |
|
| 49 |
@spaces.GPU
|
| 50 |
def ask_question(texto_extraido, question):
|
|
|
|
| 10 |
zero = torch.Tensor([0]).cuda()
|
| 11 |
print(zero.device) # <-- 'cpu' 🤔
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
|
| 14 |
|
| 15 |
+
name_model = "Qwen/Qwen2.5-7B-Instruct-GPTQ-Int8"
|
| 16 |
config.local_model_path = snapshot_download(
|
| 17 |
repo_id=name_model,
|
| 18 |
cache_dir="/root/.cache/huggingface",
|
|
|
|
| 32 |
if file_size > MAX_FILE_SIZE:
|
| 33 |
return f"O arquivo excede o limite. Por favor, realize o upload de um arquivo que contenha no máximo {MAX_FILE_SIZE/1024/1024:.1f}MB."
|
| 34 |
|
| 35 |
+
texto_extraido = doc_converter(file)
|
| 36 |
+
if texto_extraido is None:
|
| 37 |
+
return "Não foi possível extrair o texto."
|
| 38 |
+
|
| 39 |
+
return texto_extraido
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
@spaces.GPU
|
| 42 |
def ask_question(texto_extraido, question):
|
utils.py
CHANGED
|
@@ -21,9 +21,13 @@ def fix_type(file_upload):
|
|
| 21 |
|
| 22 |
@spaces.GPU
|
| 23 |
def doc_converter(file_path):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Resize image while maintaining aspect ratio
|
| 29 |
def resize_image(image, max_size):
|
|
|
|
| 21 |
|
| 22 |
@spaces.GPU
|
| 23 |
def doc_converter(file_path):
|
| 24 |
+
try:
|
| 25 |
+
converter = DocumentConverter()
|
| 26 |
+
result = converter.convert(file_path)
|
| 27 |
+
return result.document.export_to_markdown()
|
| 28 |
+
except Exception as ex:
|
| 29 |
+
print(ex)
|
| 30 |
+
return None
|
| 31 |
|
| 32 |
# Resize image while maintaining aspect ratio
|
| 33 |
def resize_image(image, max_size):
|