Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,31 @@ import random
|
|
| 6 |
import torch
|
| 7 |
import spaces
|
| 8 |
import requests
|
|
|
|
|
|
|
| 9 |
import gradio as gr
|
| 10 |
from PIL import Image
|
| 11 |
from threading import Thread
|
| 12 |
from typing import Iterable, Optional, Tuple, List
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
from transformers import (
|
| 15 |
Qwen2_5_VLForConditionalGeneration,
|
| 16 |
AutoProcessor,
|
|
|
|
| 6 |
import torch
|
| 7 |
import spaces
|
| 8 |
import requests
|
| 9 |
+
import subprocess
|
| 10 |
+
import importlib.util
|
| 11 |
import gradio as gr
|
| 12 |
from PIL import Image
|
| 13 |
from threading import Thread
|
| 14 |
from typing import Iterable, Optional, Tuple, List
|
| 15 |
|
| 16 |
+
def check_and_install_package(package_name, import_name=None, pip_name=None):
|
| 17 |
+
"""Check if a package is installed, and if not, install it."""
|
| 18 |
+
if import_name is None:
|
| 19 |
+
import_name = package_name
|
| 20 |
+
if pip_name is None:
|
| 21 |
+
pip_name = package_name
|
| 22 |
+
|
| 23 |
+
spec = importlib.util.find_spec(import_name)
|
| 24 |
+
if spec is None:
|
| 25 |
+
print(f"Installing {package_name}...")
|
| 26 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", pip_name, "-q"])
|
| 27 |
+
print(f"✓ {package_name} installed successfully")
|
| 28 |
+
return True
|
| 29 |
+
|
| 30 |
+
print("Checking and installing transformers==4.57.3 ...")
|
| 31 |
+
check_and_install_package("transformers", "transformers", "transformers==4.57.3")
|
| 32 |
+
print("Done!")
|
| 33 |
+
|
| 34 |
from transformers import (
|
| 35 |
Qwen2_5_VLForConditionalGeneration,
|
| 36 |
AutoProcessor,
|