Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
from vllm import LLM
|
| 2 |
from vllm.sampling_params import SamplingParams
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
-
from huggingface_hub import hf_hub_download
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
from pdf2image import convert_from_path
|
| 8 |
import easyocr
|
| 9 |
|
|
@@ -12,7 +12,7 @@ reader = easyocr.Reader(['en'])
|
|
| 12 |
|
| 13 |
# ... existing SYSTEM_PROMPT and load_system_prompt definitions ...
|
| 14 |
|
| 15 |
-
def
|
| 16 |
# Handle PDF files
|
| 17 |
if file_path.lower().endswith('.pdf'):
|
| 18 |
images = convert_from_path(file_path)
|
|
@@ -28,8 +28,8 @@ def process_pdf_or_image(file_path):
|
|
| 28 |
return extracted_text
|
| 29 |
|
| 30 |
def generate_response(file_path):
|
| 31 |
-
# Extract text from
|
| 32 |
-
extracted_text =
|
| 33 |
|
| 34 |
# Prepare messages for the LLM
|
| 35 |
messages = [
|
|
@@ -46,7 +46,7 @@ def generate_response(file_path):
|
|
| 46 |
]
|
| 47 |
|
| 48 |
# Initialize the LLM
|
| 49 |
-
llm = LLM(model="mistralai/Mistral-Small-3.1-24B", tokenizer_mode="mistral")
|
| 50 |
|
| 51 |
# Define sampling parameters
|
| 52 |
sampling_params = SamplingParams(max_tokens=512, temperature=0.15)
|
|
@@ -56,6 +56,12 @@ def generate_response(file_path):
|
|
| 56 |
|
| 57 |
return outputs[0].outputs[0].text
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# Gradio interface
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("# Document Processing with Mistral")
|
|
|
|
| 1 |
from vllm import LLM
|
| 2 |
from vllm.sampling_params import SamplingParams
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
import requests
|
| 6 |
+
import json
|
| 7 |
from pdf2image import convert_from_path
|
| 8 |
import easyocr
|
| 9 |
|
|
|
|
| 12 |
|
| 13 |
# ... existing SYSTEM_PROMPT and load_system_prompt definitions ...
|
| 14 |
|
| 15 |
+
def process_document(file_path):
|
| 16 |
# Handle PDF files
|
| 17 |
if file_path.lower().endswith('.pdf'):
|
| 18 |
images = convert_from_path(file_path)
|
|
|
|
| 28 |
return extracted_text
|
| 29 |
|
| 30 |
def generate_response(file_path):
|
| 31 |
+
# Extract text from document
|
| 32 |
+
extracted_text = process_document(file_path)
|
| 33 |
|
| 34 |
# Prepare messages for the LLM
|
| 35 |
messages = [
|
|
|
|
| 46 |
]
|
| 47 |
|
| 48 |
# Initialize the LLM
|
| 49 |
+
llm = LLM(model="mistralai/Mistral-Small-3.1-24B-Instruct-2503", tokenizer_mode="mistral")
|
| 50 |
|
| 51 |
# Define sampling parameters
|
| 52 |
sampling_params = SamplingParams(max_tokens=512, temperature=0.15)
|
|
|
|
| 56 |
|
| 57 |
return outputs[0].outputs[0].text
|
| 58 |
|
| 59 |
+
# Example usage
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
document_path = "path/to/your/document.pdf" # or .jpg/.png
|
| 62 |
+
response = generate_response(document_path)
|
| 63 |
+
print(response)
|
| 64 |
+
|
| 65 |
# Gradio interface
|
| 66 |
with gr.Blocks() as demo:
|
| 67 |
gr.Markdown("# Document Processing with Mistral")
|