File size: 2,213 Bytes
623da6a
 
 
 
 
 
69e65d2
623da6a
 
 
 
2948ced
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2f28df
2948ced
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
title: Micro Trend Research
emoji: "👗"
colorFrom: red
colorTo: indigo
sdk: gradio
sdk_version: "5.23.2"
app_file: app.py
pinned: false
---

# Micro-Trend Detection Gradio UI

Gradio app that ingests garment images, calls GPT-5/GPT-5 mini or Gemini 3 vision models, and returns the micro-trend JSON plus a bullet summary.

## Setup
- Python 3.11+ recommended.
- Install deps: `pip install -r requirements.txt`
- Configure secrets via environment or `settings.json` (keys mirror `sample_code/settings.json`) or `.env`:
  - `OPENAI_API_KEY`, `GEMINI_API_KEY`
  - `OPENAI_MODEL` (default `gpt-5-mini`), `OPENAI_REASONING_EFFORT`
  - `GOOGLE_GENAI_USE_VERTEXAI`, `GOOGLE_CLOUD_PROJECT`, `GOOGLE_CLOUD_LOCATION`
- The system prompt lives in `prompts/micro-trend-prompt.md` and is loaded automatically.

## Run
```bash
python app.py
```
Use `PORT`/`HOST` env vars if you need custom binding (Gradio honors them).

## How it works
- `app.py` builds the Gradio UI (multi-image upload, model dropdown, optional downscale).
- `pipeline.py` calls the unified LLM client, extracts/validates the JSON, and derives summary bullets.
- `llm_clients.py` wraps OpenAI Responses API and Gemini 3 vision.
- `schemas.py` provides structural validation and summary helper.
- `settings.py` loads config with env overrides.
- Prompt is read from `prompts/micro-trend-prompt.md` unchanged.
- Set `ENABLE_GEMINI=false` to hide Gemini from the model dropdown (useful on Spaces if Gemini isn’t available).

## Gemini auth notes
- Two modes:
  - Vertex (default): set `GOOGLE_GENAI_USE_VERTEXAI=true` and ensure ADC is available (e.g., `gcloud auth application-default login`) plus `GOOGLE_CLOUD_PROJECT`/`GOOGLE_CLOUD_LOCATION`. Confirm the chosen model exists in your Vertex region.
  - API key (HuggingFace / Studio): set `GOOGLE_GENAI_USE_VERTEXAI=false` and provide `GEMINI_API_KEY`.
  - Default Gemini model name is `gemini-3-pro-preview` (multimodal text-out). Adjust to a region-available model if needed.

## Notes
- Testing is deferred for now; add unit tests later for schema validation and summary builder.
- Downscale checkbox reduces images to 1024px for lower cost/latency. If downscale fails, original bytes are used.