Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -124,3 +124,27 @@ if image_file is not None:
|
|
124 |
|
125 |
# Clean up the temporary file after use
|
126 |
os.remove(temp_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
# Clean up the temporary file after use
|
126 |
os.remove(temp_file_path)
|
127 |
+
|
128 |
+
# Override the chat function to remove hardcoded .cuda()
|
129 |
+
def modified_chat(tokenizer, temp_file_path, ocr_type='ocr', *args, **kwargs):
|
130 |
+
# Load the image data, perform OCR and get text
|
131 |
+
with open(temp_file_path, 'rb') as f:
|
132 |
+
image_data = f.read()
|
133 |
+
|
134 |
+
# Assuming OCR process to extract text from image
|
135 |
+
# Use the OCR process here to obtain text. Replace 'extracted_text' with actual extracted text.
|
136 |
+
extracted_text = "some OCR processed text" # Placeholder, replace with actual OCR result
|
137 |
+
|
138 |
+
# Tokenize the extracted text
|
139 |
+
inputs = tokenizer(extracted_text, return_tensors="pt", truncation=True, padding=True)
|
140 |
+
|
141 |
+
# Move input_ids to the appropriate device
|
142 |
+
input_ids = inputs['input_ids'].to(device) # Move to the appropriate device
|
143 |
+
# Perform any necessary processing using the model
|
144 |
+
# Example: res = model(input_ids)
|
145 |
+
|
146 |
+
# Return the processed result
|
147 |
+
return f"Processed input: {input_ids}, OCR Type: {ocr_type}"
|
148 |
+
|
149 |
+
# Replace the model's chat method with the modified version
|
150 |
+
model.chat = modified_chat
|