Skip to content

Commit 296df7d

Browse files
Support other models in multimodal generator (#274)
* Fix CI for multimodal generator * Allowed server to accpet different models * Replaced prints with logger
1 parent afd4530 commit 296df7d

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

ai_ref_kits/multimodal_ai_visual_generator/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,26 @@ This app has two components: a FastAPI backend and a Streamlit frontend.
171171

172172
### Step 1: Run FastAPI (in Terminal 1)
173173

174+
The FastAPI backend can be configured using environment variables to specify which models to use:
175+
176+
- `IMAGE_MODEL_TYPE`: The type of image generation model to use (default: "flux.1-schnell")
177+
- `LLM_MODEL_TYPE`: The type of language model to use (default: "qwen2-7B")
178+
- `MODEL_PRECISION`: The precision to use for both models (default: "int4")
179+
180+
You can set these variables when running the application:
181+
174182
```bash
175183
cd openvino_build_deploy/ai_ref_kits/multimodal_ai_visual_generator
176184
source venv/bin/activate # On Windows: venv\Scripts\activate
185+
186+
# Run with default values
177187
uvicorn main:app --host 0.0.0.0 --port 8000
188+
189+
# Or run with custom model configuration
190+
IMAGE_MODEL_TYPE="your-image-model" LLM_MODEL_TYPE="your-llm-model" MODEL_PRECISION="int4" uvicorn main:app --host 0.0.0.0 --port 8000
178191
```
179-
> **Note:** If you're using different models, update the paths in `main.py` accordingly.
192+
193+
If no environment variables are set, the application will use the default values.
180194

181195
### Step 2: Run Streamlit UI (in Terminal 2)
182196

@@ -205,7 +219,7 @@ Branding mode:
205219
## Additional Resources
206220

207221
- Learn more about [OpenVINO](https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/overview.html)
208-
- Explore [OpenVINOs documentation](https://docs.openvino.ai/2024/home.html)
222+
- Explore [OpenVINO's documentation](https://docs.openvino.ai/2024/home.html)
209223

210224
<p align="right"><a href="#top">Back to top ⬆️</a></p>
211225

ai_ref_kits/multimodal_ai_visual_generator/ci/test.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import requests
44
import sys
5+
import os
56
from pathlib import Path
67
import logging
78

@@ -19,8 +20,8 @@
1920

2021
# ----- Configuration -----
2122
MODEL_DIR = Path("models")
22-
LLM_MODEL_TYPE = "qwen2-7B"
23-
IMAGE_MODEL_TYPE = "flux.1-schnell"
23+
LLM_MODEL_TYPE = "tiny-llama-1b-chat"
24+
IMAGE_MODEL_TYPE = "lcm"
2425
PRECISION = "int4"
2526

2627
# ----- Step 1: Export Models if Needed -----
@@ -30,7 +31,17 @@
3031

3132
# ----- Step 2: Launch FastAPI Backend -----
3233
logger.info("Launching FastAPI server...")
33-
process = subprocess.Popen([sys.executable, "-m", "uvicorn", "main:app", "--host", "127.0.0.1", "--port", "8000"])
34+
env = os.environ.copy()
35+
env.update({
36+
"IMAGE_MODEL_TYPE": IMAGE_MODEL_TYPE,
37+
"LLM_MODEL_TYPE": LLM_MODEL_TYPE,
38+
"MODEL_PRECISION": PRECISION
39+
})
40+
41+
process = subprocess.Popen(
42+
[sys.executable, "-m", "uvicorn", "main:app", "--host", "127.0.0.1", "--port", "8000"],
43+
env=env
44+
)
3445

3546
try:
3647
# Wait up to ~130 seconds (130 retries x 1s sleep) for FastAPI server to come up

ai_ref_kits/multimodal_ai_visual_generator/convert_and_optimize_text2image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import subprocess
33
import platform
44
from pathlib import Path
5-
import json
65
import os
76
import logging
87

@@ -16,6 +15,7 @@
1615
"stable-diffusionv3-large": "stabilityai/stable-diffusion-3.5-large",
1716
"stable-diffusionv3-medium": "stabilityai/stable-diffusion-3.5-medium",
1817
"stable-diffusion-2-1": "stabilityai/stable-diffusion-2-1",
18+
"lcm": "SimianLuo/LCM_Dreamshaper_v7",
1919
}
2020

2121
CRITICAL_FILES = [

ai_ref_kits/multimodal_ai_visual_generator/main.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import base64
1111
import sys
1212
import yaml
13-
import subprocess
1413
import openvino_genai as ov_genai
1514
import logging
1615
import random
@@ -47,10 +46,14 @@
4746
PROJECT_ROOT = Path(__file__).resolve().parent
4847
CONFIG_PATH = PROJECT_ROOT / "config" / "illustration.yaml"
4948

49+
# Get model types from environment variables with defaults
50+
IMAGE_MODEL_TYPE = os.getenv("IMAGE_MODEL_TYPE", "flux.1-schnell")
51+
LLM_MODEL_TYPE = os.getenv("LLM_MODEL_TYPE", "qwen2-7B")
52+
PRECISION = os.getenv("MODEL_PRECISION", "int4")
5053

51-
IMAGE_MODEL_TYPE = "flux.1-schnell"
52-
LLM_MODEL_TYPE = "qwen2-7B"
53-
PRECISION = "int4"
54+
logger.info(f"Using Image Model Type: {IMAGE_MODEL_TYPE}")
55+
logger.info(f"Using LLM Model Type: {LLM_MODEL_TYPE}")
56+
logger.info(f"Using Model Precision: {PRECISION}")
5457

5558
image_model_dir = PROJECT_ROOT / "models" / f"{IMAGE_MODEL_TYPE}-{PRECISION.upper()}"
5659
llm_model_dir = PROJECT_ROOT / "models" / f"{LLM_MODEL_TYPE}-{PRECISION.upper()}"
@@ -206,9 +209,9 @@ def callback(step, num_steps, latent):
206209

207210
# ---------- Server Start Print ----------
208211
if image_pipe or llm_pipe:
209-
print("FastAPI backend is running.")
210-
print("In a separate terminal, start the Streamlit app using:")
211-
print("streamlit run streamlit_app.py")
212+
logger.info("Demo is ready!")
213+
logger.info("FastAPI backend is running.")
214+
logger.info("In a separate terminal, start the Streamlit app using: streamlit run streamlit_app.py")
212215
else:
213-
print("FastAPI backend is running, but no models were loaded.")
214-
print("Please export models before running the Streamlit app.")
216+
logger.warning("FastAPI backend is running, but no models were loaded.")
217+
logger.warning("Please export models before running the Streamlit app.")

0 commit comments

Comments
 (0)