Commit
·
a854c6f
1
Parent(s):
4f8c3bf
tesetcase add
Browse files- .dockerignore +0 -0
- .env +0 -0
- .env.example +0 -0
- .env.new +45 -0
- Dockerfile +45 -0
- README-Docker.md +121 -0
- contbk/ai/structure +13 -20
- docker-compose-fixed.yml +39 -0
- docker-compose-new.yml +55 -0
- docker-compose-simple.yml +27 -0
- docker-compose.yml +76 -0
- gcp_auth.py +74 -0
- polls/controllers/ai/structure +14 -19
- start.ps1 +30 -0
- staticfiles/Readme.md +79 -0
- stop.ps1 +20 -0
- test_docker_config.py +120 -0
.dockerignore
ADDED
File without changes
|
.env
ADDED
File without changes
|
.env.example
ADDED
File without changes
|
.env.new
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Groq API Configuration (from README.md)
|
2 |
+
OPENAI_API_BASE=https://api.groq.com/openai/v1
|
3 |
+
OPENAI_API_KEY=your_api_key_here
|
4 |
+
MODEL_NAME=llama3-8b-8192
|
5 |
+
LOCAL_MODEL=true
|
6 |
+
|
7 |
+
# Gradio Configuration
|
8 |
+
GRADIO_SERVER_NAME=0.0.0.0
|
9 |
+
GRADIO_SERVER_PORT=7860
|
10 |
+
|
11 |
+
# Database Configuration (if needed)
|
12 |
+
DATABASE_URL=postgresql://postgres:postgres@postgres:5432/gradio_app
|
13 |
+
|
14 |
+
# Django Configuration
|
15 |
+
DJANGO_SECRET_KEY=your-secret-key-here
|
16 |
+
DJANGO_DEBUG=False
|
17 |
+
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
|
18 |
+
|
19 |
+
# Google Cloud Configuration (Base64 encoded to avoid issues)
|
20 |
+
GOOGLE_APPLICATION_CREDENTIALS_CONTENT={"type":"service_account","project_id":"urlounge74620","private_key_id":"f24a8ae1770ddebd6ce9a0d113f605496227745e","private_key":"-----BEGIN PRIVATE KEY-----\nMIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQC3XR4hg/vKb2MV\nVn3XX2n826kbOrZw3nqS/SUDqi084yJAqaHbbJR+ht8axsjBmltXL2mninpQSHJI\n4OCfoxNLOpSKe2cySYdDbtASHDpIRH/A8rnW0GAVoD5MBkxmQ5WEmyo6+vJAg8Rq\nuzXEfNPDangim9mJ5n7Egy/PU84kNh3G7DBti20/5rFr7YHS5rhuwisdB5zD7Rri\n9HEoBU1oRDlZBUuFMuQa7cgGUMC70MF7+ghgzxAThgh216fo5wrjdv13GtJX1Qlp\n6xMoxacscHzukPp1G/Mzb8aPLoO/GmyPxCIAF7pyU9U34V8gLSHKH5I6SdiCO0bN\nI89JKsZ3AgMBAAECgf8IlxolLIsqByDOgJlMY/0Cs+IV4LJjSxBq1nzMhcntYqBy\nds/f9OdGVZ1jBt+PA6EMVlmvrB+vTslULZCvweI91cSceQs6AMNiVRWhpBaRZ7wm\nYjtsJ+41K2jJFjGdznr+9AVdZEpcq2eApe50k8c4PlDdWkfqE2UpbF8AMOUoay1T\nafwo2xdfD5xquFcrwzZ8DYOosUQijIi99dquCeNKbYRe4lZMebV/QVzdVL6uSsYZ\ntOUAV0wQ3eC98XfNF9Bg61eTGCMwcaKDEJkgS/hqFZf6LndRHGNYksKyb1d+/OMv\n0eSuviqNsTubwzBvUTD+lUbjjV5dBRVBnVPeSPUCgYEA+qfFjl7w1Typ8ipIF51k\nKTP+h3cfNy0zMmuig4uFgDRhw+X/eJKWdFJTaaIqLPbynzBKmll992Cyf9owZypN\nvxC43geEtoK3UBWFkvbrQpFNBasHACM4ovf9ykOd63vZvbDqGv7n+E3CWHVD2Wlp\nxBqOAK7kM2QWkQS2CBOhjQsCgYEAu0YHGGvSxc7ubIs1YI4MtyRE2FNIgneBus+Y\nlrK0r9hkeLmtXtTVUjescbXKP0J/e3sqL7jFFBlPbUfl2hQClOHxpvC9W801B2ht\nB0bKuqLcqAF360LxQVasR14EC6vSrjY9tdawYzwFLkCDMMUJDSFN1RCPwkPSxIrq\nWy5P18UCgYBx5NgEuCkwi28hZYr6h/7iJgkK3trlRHmV+IiQw033ElY2IIUz8U/C\nLUJPpmsJoXBfWx8bAX0Wce7J34fM6NEI9305DiuEjuLi1dSrEd2WktVvtOXqbxam\nHo9IX+8a+FzZL9FAUQFwt0yOy0H4QUjY3cQWlWGF5H3IiV55TwpCPwKBgBH/Jsto\nATdVLYBs2FJRFFO9PohzaHJxPZxQOt+wiMClUPJxFYIZfe6Kvx2mVKtDnrClI2a2\noOnPjNx5nlMYvS7Fj811MR1TWRc/J8sdOHo7EG1sxrNrGXgn9iJdnJHqjzKCr+d7\nDPNHspVFMZpCPekDbC+CLKoheaxWtgsWSvpAoGACOoyu3gMv29eh+6wMsA9Qhsb\nhkbAl8oUQyEh1O45D/bbcYJTm8Ue98m8csIRYRdUWDm/DxeJD9v+uUZwVkMK1bNQ\nuJyWFtVdRwsf5jnbD11gPs4LZyW/ZvJKtiiBtWPqeK0gSPqKP1HY2TYvLIsBlSOY\nc2/xwB1+HB+TfuZwItM=\n-----END PRIVATE KEY-----\n","client_email":"[email protected]","client_id":"113873685578046298528","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/t-louge%40urlounge74620.iam.gserviceaccount.com","universe_domain":"googleapis.com"}
|
21 |
+
GOOGLE_PROJECT_ID=urlounge74620
|
22 |
+
GOOGLE_CLIENT_EMAIL=t-louge@urlounge74620.iam.gserviceaccount.com
|
23 |
+
|
24 |
+
# Additional Environment Variables
|
25 |
+
APPSHEET_APPID=YOUR_VALUE_HERE
|
26 |
+
APPSHEET_KEY=YOUR_VALUE_HERE
|
27 |
+
ASSSHEET_APPID=YOUR_VALUE_HERE
|
28 |
+
ChannelAccessToken=YOUR_VALUE_HERE
|
29 |
+
ChannelID=YOUR_VALUE_HERE
|
30 |
+
ChannelSecret=YOUR_VALUE_HERE
|
31 |
+
WEBHOOK_GAS=YOUR_VALUE_HERE
|
32 |
+
WEBHOOK_URL=YOUR_VALUE_HERE
|
33 |
+
api_key=YOUR_VALUE_HERE
|
34 |
+
chat_url=YOUR_VALUE_HERE
|
35 |
+
hf_token=YOUR_VALUE_HERE
|
36 |
+
n8nhook=YOUR_VALUE_HERE
|
37 |
+
openinterpreter_secret=YOUR_VALUE_HERE
|
38 |
+
postgre_host=YOUR_VALUE_HERE
|
39 |
+
postgre_pass=YOUR_VALUE_HERE
|
40 |
+
postgre_url=YOUR_VALUE_HERE
|
41 |
+
postgre_user=YOUR_VALUE_HERE
|
42 |
+
token=YOUR_VALUE_HERE
|
43 |
+
github_user=YOUR_VALUE_HERE
|
44 |
+
github_token=YOUR_VALUE_HERE
|
45 |
+
TOOL_KIT_DIR=usage
|
Dockerfile
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use Python 3.11 as base image
|
2 |
+
FROM python:3.11-slim
|
3 |
+
|
4 |
+
# Set working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Set environment variables
|
8 |
+
ENV PYTHONUNBUFFERED=1
|
9 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
10 |
+
|
11 |
+
# Install system dependencies
|
12 |
+
RUN apt-get update && apt-get install -y \
|
13 |
+
gcc \
|
14 |
+
g++ \
|
15 |
+
curl \
|
16 |
+
git \
|
17 |
+
jq \
|
18 |
+
&& rm -rf /var/lib/apt/lists/*
|
19 |
+
|
20 |
+
# Copy requirements first for better caching
|
21 |
+
COPY requirements.txt .
|
22 |
+
|
23 |
+
# Install Python dependencies
|
24 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
25 |
+
pip install --no-cache-dir gradio==4.29.0 && \
|
26 |
+
pip install --no-cache-dir google-cloud-storage google-auth google-auth-oauthlib google-auth-httplib2 && \
|
27 |
+
pip install --no-cache-dir -r requirements.txt
|
28 |
+
|
29 |
+
# Copy the application code
|
30 |
+
COPY . .
|
31 |
+
|
32 |
+
# Create directories for gradio cache and temp files
|
33 |
+
RUN mkdir -p /app/gradio_cached_examples && \
|
34 |
+
mkdir -p /app/cache && \
|
35 |
+
chmod -R 755 /app
|
36 |
+
|
37 |
+
# Expose port
|
38 |
+
EXPOSE 7860
|
39 |
+
|
40 |
+
# Health check
|
41 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
42 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
43 |
+
|
44 |
+
# Run the application
|
45 |
+
CMD ["python", "app.py"]
|
README-Docker.md
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 🦀 Gradio FastAPI Django Main - Docker Setup
|
2 |
+
|
3 |
+
Based on the configuration in README.md:
|
4 |
+
- **Title**: Gradio fastapi_django_main
|
5 |
+
- **Emoji**: 🦀
|
6 |
+
- **SDK**: Gradio 4.29.0
|
7 |
+
- **App File**: app.py
|
8 |
+
|
9 |
+
## Quick Start
|
10 |
+
|
11 |
+
### Prerequisites
|
12 |
+
- Docker Desktop installed and running
|
13 |
+
- PowerShell (Windows) or Bash (Linux/macOS)
|
14 |
+
|
15 |
+
### 🚀 Start Application
|
16 |
+
```powershell
|
17 |
+
# Windows
|
18 |
+
.\start.ps1
|
19 |
+
|
20 |
+
# Or manually:
|
21 |
+
docker-compose up --build -d
|
22 |
+
```
|
23 |
+
|
24 |
+
### 🛑 Stop Application
|
25 |
+
```powershell
|
26 |
+
# Windows
|
27 |
+
.\stop.ps1
|
28 |
+
|
29 |
+
# Or manually:
|
30 |
+
docker-compose down
|
31 |
+
```
|
32 |
+
|
33 |
+
## Configuration
|
34 |
+
|
35 |
+
### Environment Variables
|
36 |
+
Copy `.env.example` to `.env` and update the values:
|
37 |
+
|
38 |
+
```bash
|
39 |
+
# Groq API Configuration
|
40 |
+
OPENAI_API_BASE=https://api.groq.com/openai/v1
|
41 |
+
OPENAI_API_KEY=your_actual_api_key_here
|
42 |
+
MODEL_NAME=llama3-8b-8192
|
43 |
+
LOCAL_MODEL=true
|
44 |
+
|
45 |
+
# Gradio Configuration
|
46 |
+
GRADIO_SERVER_NAME=0.0.0.0
|
47 |
+
GRADIO_SERVER_PORT=7860
|
48 |
+
```
|
49 |
+
|
50 |
+
## Services
|
51 |
+
|
52 |
+
### Main Application
|
53 |
+
- **Container**: `gradio-fastapi-django-main`
|
54 |
+
- **Port**: 7860
|
55 |
+
- **URL**: http://localhost:7860
|
56 |
+
|
57 |
+
### Features
|
58 |
+
- Gradio 4.29.0 Web Interface
|
59 |
+
- FastAPI Backend
|
60 |
+
- Django Integration
|
61 |
+
- Groq API Support
|
62 |
+
- Health Checks
|
63 |
+
- Auto-restart on failure
|
64 |
+
|
65 |
+
## Docker Commands
|
66 |
+
|
67 |
+
```bash
|
68 |
+
# Build only
|
69 |
+
docker-compose build
|
70 |
+
|
71 |
+
# Start in foreground (see logs)
|
72 |
+
docker-compose up
|
73 |
+
|
74 |
+
# Start in background
|
75 |
+
docker-compose up -d
|
76 |
+
|
77 |
+
# View logs
|
78 |
+
docker-compose logs -f
|
79 |
+
|
80 |
+
# Check status
|
81 |
+
docker-compose ps
|
82 |
+
|
83 |
+
# Stop and remove
|
84 |
+
docker-compose down
|
85 |
+
|
86 |
+
# Rebuild and start
|
87 |
+
docker-compose up --build
|
88 |
+
|
89 |
+
# Clean up everything
|
90 |
+
docker-compose down -v --remove-orphans
|
91 |
+
docker system prune -f
|
92 |
+
```
|
93 |
+
|
94 |
+
## Troubleshooting
|
95 |
+
|
96 |
+
### Container won't start
|
97 |
+
1. Check Docker Desktop is running
|
98 |
+
2. Check logs: `docker-compose logs`
|
99 |
+
3. Verify `.env` file exists and has correct values
|
100 |
+
4. Ensure port 7860 is not in use
|
101 |
+
|
102 |
+
### API Key Issues
|
103 |
+
1. Update `OPENAI_API_KEY` in `.env` file
|
104 |
+
2. Restart containers: `docker-compose restart`
|
105 |
+
|
106 |
+
### Performance Issues
|
107 |
+
1. Allocate more memory to Docker Desktop
|
108 |
+
2. Check container resources: `docker stats`
|
109 |
+
|
110 |
+
## Development
|
111 |
+
|
112 |
+
### Local Development with Docker
|
113 |
+
```bash
|
114 |
+
# Mount source code for live reloading
|
115 |
+
docker-compose -f docker-compose.dev.yml up
|
116 |
+
```
|
117 |
+
|
118 |
+
### Access Container Shell
|
119 |
+
```bash
|
120 |
+
docker-compose exec gradio-fastapi-django bash
|
121 |
+
```
|
contbk/ai/structure
CHANGED
@@ -1,25 +1,18 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
src
|
4 |
__init__.py
|
5 |
-
|
6 |
__init__.py
|
7 |
-
|
8 |
-
|
9 |
-
user.py
|
10 |
-
services
|
11 |
__init__.py
|
12 |
-
|
13 |
-
|
14 |
-
user_service.py
|
15 |
-
repositories
|
16 |
__init__.py
|
17 |
-
|
18 |
-
|
19 |
-
user_repository.py
|
20 |
-
main.py
|
21 |
-
tests
|
22 |
__init__.py
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
1 |
+
project/
|
2 |
+
app/
|
|
|
3 |
__init__.py
|
4 |
+
controllers/
|
5 |
__init__.py
|
6 |
+
scraping.py
|
7 |
+
models/
|
|
|
|
|
8 |
__init__.py
|
9 |
+
product.py
|
10 |
+
services/
|
|
|
|
|
11 |
__init__.py
|
12 |
+
scraping_service.py
|
13 |
+
utils/
|
|
|
|
|
|
|
14 |
__init__.py
|
15 |
+
logger.py
|
16 |
+
requirements.txt
|
17 |
+
run.sh
|
18 |
+
README.md
|
docker-compose-fixed.yml
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.8'
|
2 |
+
|
3 |
+
services:
|
4 |
+
gradio-fastapi-django:
|
5 |
+
build:
|
6 |
+
context: .
|
7 |
+
dockerfile: Dockerfile
|
8 |
+
container_name: gradio-fastapi-django-main
|
9 |
+
ports:
|
10 |
+
- "7860:7860"
|
11 |
+
environment:
|
12 |
+
- PYTHONUNBUFFERED=1
|
13 |
+
- GRADIO_SERVER_NAME=0.0.0.0
|
14 |
+
- GRADIO_SERVER_PORT=7860
|
15 |
+
- OPENAI_API_BASE=${OPENAI_API_BASE:-https://api.groq.com/openai/v1}
|
16 |
+
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
17 |
+
- MODEL_NAME=${MODEL_NAME:-llama3-8b-8192}
|
18 |
+
- LOCAL_MODEL=${LOCAL_MODEL:-true}
|
19 |
+
- GOOGLE_APPLICATION_CREDENTIALS_CONTENT=${GOOGLE_APPLICATION_CREDENTIALS_CONTENT}
|
20 |
+
- GOOGLE_PROJECT_ID=${GOOGLE_PROJECT_ID}
|
21 |
+
- GOOGLE_CLIENT_EMAIL=${GOOGLE_CLIENT_EMAIL}
|
22 |
+
volumes:
|
23 |
+
- ./cache:/app/cache
|
24 |
+
- ./gradio_cached_examples:/app/gradio_cached_examples
|
25 |
+
- ./static:/app/static
|
26 |
+
- ./templates:/app/templates
|
27 |
+
restart: unless-stopped
|
28 |
+
healthcheck:
|
29 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/health"]
|
30 |
+
interval: 30s
|
31 |
+
timeout: 10s
|
32 |
+
retries: 3
|
33 |
+
start_period: 30s
|
34 |
+
networks:
|
35 |
+
- gradio-network
|
36 |
+
|
37 |
+
networks:
|
38 |
+
gradio-network:
|
39 |
+
driver: bridge
|
docker-compose-new.yml
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.8'
|
2 |
+
|
3 |
+
services:
|
4 |
+
gradio-fastapi-django:
|
5 |
+
build:
|
6 |
+
context: .
|
7 |
+
dockerfile: Dockerfile
|
8 |
+
container_name: gradio-fastapi-django-main
|
9 |
+
ports:
|
10 |
+
- "7860:7860"
|
11 |
+
environment:
|
12 |
+
- PYTHONUNBUFFERED=1
|
13 |
+
- GRADIO_SERVER_NAME=0.0.0.0
|
14 |
+
- GRADIO_SERVER_PORT=7860
|
15 |
+
- OPENAI_API_BASE=${OPENAI_API_BASE:-https://api.groq.com/openai/v1}
|
16 |
+
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
17 |
+
- MODEL_NAME=${MODEL_NAME:-llama3-8b-8192}
|
18 |
+
- LOCAL_MODEL=${LOCAL_MODEL:-true}
|
19 |
+
- GOOGLE_APPLICATION_CREDENTIALS_CONTENT=${GOOGLE_APPLICATION_CREDENTIALS_CONTENT}
|
20 |
+
- GOOGLE_PROJECT_ID=${GOOGLE_PROJECT_ID}
|
21 |
+
- GOOGLE_CLIENT_EMAIL=${GOOGLE_CLIENT_EMAIL}
|
22 |
+
volumes:
|
23 |
+
- ./cache:/app/cache
|
24 |
+
- ./gradio_cached_examples:/app/gradio_cached_examples
|
25 |
+
- ./static:/app/static
|
26 |
+
- ./templates:/app/templates
|
27 |
+
restart: unless-stopped
|
28 |
+
healthcheck:
|
29 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/health"]
|
30 |
+
interval: 30s
|
31 |
+
timeout: 10s
|
32 |
+
retries: 3
|
33 |
+
start_period: 30s
|
34 |
+
networks:
|
35 |
+
- gradio-network
|
36 |
+
|
37 |
+
# Optional: Add a database service if needed
|
38 |
+
# postgres:
|
39 |
+
# image: postgres:15-alpine
|
40 |
+
# container_name: postgres-db
|
41 |
+
# environment:
|
42 |
+
# POSTGRES_DB: gradio_app
|
43 |
+
# POSTGRES_USER: postgres
|
44 |
+
# POSTGRES_PASSWORD: postgres
|
45 |
+
# volumes:
|
46 |
+
# - postgres_data:/var/lib/postgresql/data
|
47 |
+
# networks:
|
48 |
+
# - gradio-network
|
49 |
+
|
50 |
+
networks:
|
51 |
+
gradio-network:
|
52 |
+
driver: bridge
|
53 |
+
|
54 |
+
volumes:
|
55 |
+
postgres_data:
|
docker-compose-simple.yml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.8'
|
2 |
+
|
3 |
+
services:
|
4 |
+
gradio-fastapi-django:
|
5 |
+
build:
|
6 |
+
context: .
|
7 |
+
dockerfile: Dockerfile
|
8 |
+
container_name: gradio-fastapi-django-main
|
9 |
+
ports:
|
10 |
+
- "7860:7860"
|
11 |
+
env_file:
|
12 |
+
- .env
|
13 |
+
volumes:
|
14 |
+
- ./cache:/app/cache
|
15 |
+
- ./static:/app/static
|
16 |
+
- ./templates:/app/templates
|
17 |
+
restart: unless-stopped
|
18 |
+
healthcheck:
|
19 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/health"]
|
20 |
+
interval: 30s
|
21 |
+
timeout: 10s
|
22 |
+
retries: 3
|
23 |
+
start_period: 30s
|
24 |
+
|
25 |
+
networks:
|
26 |
+
default:
|
27 |
+
driver: bridge
|
docker-compose.yml
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.8'
|
2 |
+
|
3 |
+
services:
|
4 |
+
gradio-fastapi-django:
|
5 |
+
build:
|
6 |
+
context: .
|
7 |
+
dockerfile: Dockerfile
|
8 |
+
container_name: gradio-fastapi-django-main
|
9 |
+
ports:
|
10 |
+
- "7860:7860"
|
11 |
+
environment:
|
12 |
+
- PYTHONUNBUFFERED=1
|
13 |
+
- GRADIO_SERVER_NAME=0.0.0.0
|
14 |
+
- GRADIO_SERVER_PORT=7860
|
15 |
+
- OPENAI_API_BASE=${OPENAI_API_BASE:-https://api.groq.com/openai/v1}
|
16 |
+
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
17 |
+
- MODEL_NAME=${MODEL_NAME:-llama3-8b-8192}
|
18 |
+
- LOCAL_MODEL=${LOCAL_MODEL:-true}
|
19 |
+
- GOOGLE_APPLICATION_CREDENTIALS_CONTENT=${GOOGLE_APPLICATION_CREDENTIALS_CONTENT}
|
20 |
+
- GOOGLE_PROJECT_ID=${GOOGLE_PROJECT_ID}
|
21 |
+
- GOOGLE_CLIENT_EMAIL=${GOOGLE_CLIENT_EMAIL}
|
22 |
+
- APPSHEET_APPID=${APPSHEET_APPID}
|
23 |
+
- APPSHEET_KEY=${APPSHEET_KEY}
|
24 |
+
- ASSSHEET_APPID=${ASSSHEET_APPID}
|
25 |
+
- ChannelAccessToken=${ChannelAccessToken}
|
26 |
+
- ChannelID=${ChannelID}
|
27 |
+
- ChannelSecret=${ChannelSecret}
|
28 |
+
- WEBHOOK_GAS=${WEBHOOK_GAS}
|
29 |
+
- WEBHOOK_URL=${WEBHOOK_URL}
|
30 |
+
- api_key=${api_key}
|
31 |
+
- chat_url=${chat_url}
|
32 |
+
- hf_token=${hf_token}
|
33 |
+
- n8nhook=${n8nhook}
|
34 |
+
- openinterpreter_secret=${openinterpreter_secret}
|
35 |
+
- postgre_host=${postgre_host}
|
36 |
+
- postgre_pass=${postgre_pass}
|
37 |
+
- postgre_url=${postgre_url}
|
38 |
+
- postgre_user=${postgre_user}
|
39 |
+
- token=${token}
|
40 |
+
- github_user=${github_user}
|
41 |
+
- github_token=${github_token}
|
42 |
+
- TOOL_KIT_DIR=usage
|
43 |
+
volumes:
|
44 |
+
- ./cache:/app/cache
|
45 |
+
- ./gradio_cached_examples:/app/gradio_cached_examples
|
46 |
+
- ./static:/app/static
|
47 |
+
- ./templates:/app/templates
|
48 |
+
restart: unless-stopped
|
49 |
+
healthcheck:
|
50 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/health"]
|
51 |
+
interval: 30s
|
52 |
+
timeout: 10s
|
53 |
+
retries: 3
|
54 |
+
start_period: 30s
|
55 |
+
networks:
|
56 |
+
- gradio-network
|
57 |
+
|
58 |
+
# Optional: Add a database service if needed
|
59 |
+
# postgres:
|
60 |
+
# image: postgres:15-alpine
|
61 |
+
# container_name: postgres-db
|
62 |
+
# environment:
|
63 |
+
# POSTGRES_DB: gradio_app
|
64 |
+
# POSTGRES_USER: postgres
|
65 |
+
# POSTGRES_PASSWORD: postgres
|
66 |
+
# volumes:
|
67 |
+
# - postgres_data:/var/lib/postgresql/data
|
68 |
+
# networks:
|
69 |
+
# - gradio-network
|
70 |
+
|
71 |
+
networks:
|
72 |
+
gradio-network:
|
73 |
+
driver: bridge
|
74 |
+
|
75 |
+
volumes:
|
76 |
+
postgres_data:
|
gcp_auth.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Google Cloud Authentication Helper
|
4 |
+
This script handles Google Cloud authentication using environment variables.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import os
|
8 |
+
import json
|
9 |
+
import tempfile
|
10 |
+
from google.auth import default
|
11 |
+
from google.cloud import storage
|
12 |
+
|
13 |
+
|
14 |
+
def setup_gcp_credentials():
|
15 |
+
"""Setup Google Cloud credentials from environment variables."""
|
16 |
+
|
17 |
+
# Get credentials content from environment variable
|
18 |
+
creds_content = os.getenv('GOOGLE_APPLICATION_CREDENTIALS_CONTENT')
|
19 |
+
|
20 |
+
if creds_content:
|
21 |
+
# Parse JSON credentials
|
22 |
+
try:
|
23 |
+
creds_dict = json.loads(creds_content)
|
24 |
+
|
25 |
+
# Create temporary credentials file
|
26 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
27 |
+
json.dump(creds_dict, f)
|
28 |
+
temp_creds_path = f.name
|
29 |
+
|
30 |
+
# Set environment variable for Google Cloud SDK
|
31 |
+
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = temp_creds_path
|
32 |
+
|
33 |
+
print(f"✅ Google Cloud credentials configured successfully")
|
34 |
+
print(f"📁 Project ID: {creds_dict.get('project_id', 'N/A')}")
|
35 |
+
print(f"📧 Client Email: {creds_dict.get('client_email', 'N/A')}")
|
36 |
+
|
37 |
+
return temp_creds_path
|
38 |
+
|
39 |
+
except json.JSONDecodeError as e:
|
40 |
+
print(f"❌ Error parsing Google Cloud credentials: {e}")
|
41 |
+
return None
|
42 |
+
else:
|
43 |
+
print("⚠️ No Google Cloud credentials found in environment variables")
|
44 |
+
return None
|
45 |
+
|
46 |
+
|
47 |
+
def test_gcp_connection():
|
48 |
+
"""Test Google Cloud connection."""
|
49 |
+
try:
|
50 |
+
# Test authentication
|
51 |
+
credentials, project = default()
|
52 |
+
print(f"✅ Google Cloud authentication successful")
|
53 |
+
print(f"📁 Project: {project}")
|
54 |
+
|
55 |
+
# Test Cloud Storage access
|
56 |
+
client = storage.Client()
|
57 |
+
buckets = list(client.list_buckets())
|
58 |
+
print(f"📦 Found {len(buckets)} storage buckets")
|
59 |
+
|
60 |
+
return True
|
61 |
+
except Exception as e:
|
62 |
+
print(f"❌ Google Cloud connection test failed: {e}")
|
63 |
+
return False
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
# Setup credentials
|
68 |
+
creds_path = setup_gcp_credentials()
|
69 |
+
|
70 |
+
if creds_path:
|
71 |
+
# Test connection
|
72 |
+
test_gcp_connection()
|
73 |
+
else:
|
74 |
+
print("❌ Failed to setup Google Cloud credentials")
|
polls/controllers/ai/structure
CHANGED
@@ -1,25 +1,20 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
src
|
4 |
__init__.py
|
5 |
-
|
|
|
6 |
__init__.py
|
7 |
-
account.py
|
8 |
-
transaction.py
|
9 |
user.py
|
10 |
-
|
|
|
11 |
__init__.py
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
repositories
|
16 |
__init__.py
|
17 |
-
|
18 |
-
|
19 |
-
user_repository.py
|
20 |
-
main.py
|
21 |
-
tests
|
22 |
__init__.py
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
1 |
+
api/
|
2 |
+
app/
|
|
|
3 |
__init__.py
|
4 |
+
main.py
|
5 |
+
models/
|
6 |
__init__.py
|
|
|
|
|
7 |
user.py
|
8 |
+
team.py
|
9 |
+
schemas/
|
10 |
__init__.py
|
11 |
+
user.py
|
12 |
+
team.py
|
13 |
+
routers/
|
|
|
14 |
__init__.py
|
15 |
+
users.py
|
16 |
+
teams.py
|
|
|
|
|
|
|
17 |
__init__.py
|
18 |
+
app.py
|
19 |
+
requirements.txt
|
20 |
+
.gitignore
|
start.ps1
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gradio FastAPI Django Main - Docker Compose Start Script
|
2 |
+
# Based on README.md configuration: Gradio 4.29.0, app.py
|
3 |
+
|
4 |
+
Write-Host "🦀 Starting Gradio FastAPI Django Main Application" -ForegroundColor Cyan
|
5 |
+
Write-Host "Emoji: 🦀" -ForegroundColor Yellow
|
6 |
+
Write-Host "SDK: Gradio 4.29.0" -ForegroundColor Green
|
7 |
+
Write-Host "App File: app.py" -ForegroundColor Blue
|
8 |
+
|
9 |
+
# Check if Docker is running
|
10 |
+
if (!(Get-Process "Docker Desktop" -ErrorAction SilentlyContinue)) {
|
11 |
+
Write-Host "❌ Docker Desktop is not running. Please start Docker Desktop first." -ForegroundColor Red
|
12 |
+
exit 1
|
13 |
+
}
|
14 |
+
|
15 |
+
# Build and start the containers
|
16 |
+
Write-Host "🔨 Building and starting containers..." -ForegroundColor Cyan
|
17 |
+
docker-compose up --build -d
|
18 |
+
|
19 |
+
if ($LASTEXITCODE -eq 0) {
|
20 |
+
Write-Host "✅ Application started successfully!" -ForegroundColor Green
|
21 |
+
Write-Host "🌐 Application is running at: http://localhost:7860" -ForegroundColor Blue
|
22 |
+
Write-Host "📊 Container status:" -ForegroundColor Yellow
|
23 |
+
docker-compose ps
|
24 |
+
|
25 |
+
Write-Host "`n📝 To view logs: docker-compose logs -f" -ForegroundColor Cyan
|
26 |
+
Write-Host "🛑 To stop: docker-compose down" -ForegroundColor Cyan
|
27 |
+
} else {
|
28 |
+
Write-Host "❌ Failed to start application. Check the logs:" -ForegroundColor Red
|
29 |
+
docker-compose logs
|
30 |
+
}
|
staticfiles/Readme.md
CHANGED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# これは何か
|
2 |
+
チャット欄に寄せられるコメントに自動で応答をしながら進行をする、AIによるYouTube LIVE配信を行うためのサンプルです。
|
3 |
+
|
4 |
+
# 準備
|
5 |
+
|
6 |
+
AIによる雑談配信を行うためのソースコードはすでに実装済みです。
|
7 |
+
下記の準備が必要な項目のみ設定が必要です。
|
8 |
+
|
9 |
+
## 1. 画像の用意
|
10 |
+
下記の3つの名前の画像を用意し、ルートディレクトリ内に設置してください。
|
11 |
+
|
12 |
+
- chara.png
|
13 |
+
- chara_blinking.png
|
14 |
+
- background.png
|
15 |
+
|
16 |
+
※`chara_blinking.png`は瞬きをしているキャラクターの静止画です。
|
17 |
+
※`background.png`は背景の画像です。
|
18 |
+
画像の名前を変更したい場合は、適宜index.html、aivtuber.js内を変更してください。
|
19 |
+
|
20 |
+
## 2. meboのAPIキー・エージェントIDの設定
|
21 |
+
[mebo](https://mebo.work)を利用して、会話が可能なAIキャラクターを作成してください。
|
22 |
+
mebo内の[Chara.AI Generator](https://zenn.dev/makunugi/articles/ebecbb5de562d6)という機能を利用すると、スムーズにAIキャラクターが作成できます。
|
23 |
+
|
24 |
+
AIキャラクターを作成したら、meboの公開設定画面でAIキャラクターを限定公開し、「APIを有効化」してください。
|
25 |
+
|
26 |
+
APIを有効化するとAPIキーとエージェントIDを取得できます。
|
27 |
+
|
28 |
+
APIキーを取得したら、`aivtuber.js`を開き、下記の箇所にAPIキーとエージェントIDを入力しましょう。
|
29 |
+
|
30 |
+
```js
|
31 |
+
const MEBO_API_KEY = "<meboのAPIキーを入力してください。>";
|
32 |
+
const MEBO_AGENT_ID = "<meboのAgent IDを入力してください。>";
|
33 |
+
```
|
34 |
+
|
35 |
+
## 3. VOICEVOXをインストール
|
36 |
+
声の読み上げはVOICEVOXを利用します。
|
37 |
+
下記からVOICEVOXをインストールし、起動してください。VOICEVOXが起動されることで、ローカル環境にAPIが立ち上がります。
|
38 |
+
[VOICEVOX公式サイト](https://voicevox.hiroshiba.jp/)
|
39 |
+
|
40 |
+
|
41 |
+
```js
|
42 |
+
const VOICE_VOX_API_URL = "http://localhost:50021";
|
43 |
+
```
|
44 |
+
デフォルトで上記が`aivtuber.js`に設定されています。ポート番号を変更する際は、上記のURLを適宜変更してください。
|
45 |
+
|
46 |
+
尚、VOICEVOXを利用してYouTube配信をする場合は、ライセンス表記が必要です。概要欄などできちんと明記をして利用しましょう。
|
47 |
+
[VOICEVOX利用規約](https://voicevox.hiroshiba.jp/term/)
|
48 |
+
|
49 |
+
## 4. YouTubeライブ配信のVIDEO IDを設定
|
50 |
+
YouTubeのライブ配信の準備が整ったら、ライブ配信の動画のURLに末尾にあるVideo IDを`aivtuber.js`の下記の箇所に入力してください。
|
51 |
+
|
52 |
+
```js
|
53 |
+
const YOUTUBE_VIDEO_ID = '<YouTube Video IDを入力してください。>';
|
54 |
+
```
|
55 |
+
|
56 |
+
Video IDは動画のURLの末尾にある「v=」より後の文字列です。
|
57 |
+
`https://www.youtube.com/watch?v=x12345667`
|
58 |
+
上記であれば、Video IDは「x12345667」になります。
|
59 |
+
|
60 |
+
|
61 |
+
## 5. YouTube Data APIのAPIキーの用意
|
62 |
+
YouTubeライブ配信のコメントを取得するため、YouTube Data APIのAPIキーを利用します。
|
63 |
+
APIキーの取得方法は、[こちら](https://qiita.com/shinkai_/items/10a400c25de270cb02e4#:~:text=%E8%AA%8D%E8%A8%BC%E6%83%85%E5%A0%B1%E3%81%AE%E4%BD%9C%E6%88%90%EF%BC%88API%E3%82%AD%E3%83%BC%E3%81%AE%E4%BD%9C%E6%88%90%EF%BC%89,-%E3%80%8C%E8%AA%8D%E8%A8%BC%E6%83%85%E5%A0%B1%E3%80%8D%E3%82%92&text=%E3%80%8C%E8%AA%8D%E8%A8%BC%E6%83%85%E5%A0%B1%E3%82%92%E4%BD%9C%E6%88%90%E3%80%8D%E3%82%92,%E4%BF%9D%E5%AD%98%E3%80%8D%E3%82%92%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%97%E3%81%BE%E3%81%99%E3%80%82)の記事が大変わかりやすくまとめられていました。
|
64 |
+
|
65 |
+
APIキーを取得したら、`aivtuber.js`の下記の箇所に入力しましょう。
|
66 |
+
|
67 |
+
```js
|
68 |
+
const YOUTUBE_DATA_API_KEY = '<YouTube Data APIのAPIキーを入力してください。>';
|
69 |
+
```
|
70 |
+
|
71 |
+
# 動作確認
|
72 |
+
`index.html`をブラウザで開きましょう。
|
73 |
+
ページ下部のテキスト入力欄にコメントを入力し「送信」ボタンを押して、無事応答が返ってくれば成功です。
|
74 |
+
|
75 |
+
# LINE開始
|
76 |
+
動作確認が完了したら、「LIVE開始」を押しましょう。
|
77 |
+
YouTube LIVEのコメントに対して応答を返すようになります。
|
78 |
+
[OBS](https://obsproject.com/ja/download)などの画面配信が可能なツールを利用して、AI VTuberを表示しているブラウザのキャプチャをYouTubeに配信しましょう。
|
79 |
+
|
stop.ps1
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gradio FastAPI Django Main - Docker Compose Stop Script
|
2 |
+
|
3 |
+
Write-Host "🛑 Stopping Gradio FastAPI Django Main Application" -ForegroundColor Red
|
4 |
+
|
5 |
+
# Stop and remove containers
|
6 |
+
docker-compose down
|
7 |
+
|
8 |
+
if ($LASTEXITCODE -eq 0) {
|
9 |
+
Write-Host "✅ Application stopped successfully!" -ForegroundColor Green
|
10 |
+
} else {
|
11 |
+
Write-Host "❌ Failed to stop application properly." -ForegroundColor Red
|
12 |
+
}
|
13 |
+
|
14 |
+
# Optional: Remove unused volumes and images
|
15 |
+
$cleanup = Read-Host "Do you want to clean up unused Docker resources? (y/N)"
|
16 |
+
if ($cleanup -eq "y" -or $cleanup -eq "Y") {
|
17 |
+
Write-Host "🧹 Cleaning up Docker resources..." -ForegroundColor Yellow
|
18 |
+
docker system prune -f
|
19 |
+
Write-Host "✅ Cleanup completed!" -ForegroundColor Green
|
20 |
+
}
|
test_docker_config.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Docker環境設定テストスクリプト
|
4 |
+
README.md仕様: Gradio 4.29.0, 🦀 emoji, app.py
|
5 |
+
"""
|
6 |
+
|
7 |
+
import os
|
8 |
+
import json
|
9 |
+
import sys
|
10 |
+
|
11 |
+
def test_environment_variables():
|
12 |
+
"""環境変数の設定をテスト"""
|
13 |
+
print("🦀 Docker環境設定テスト - Gradio FastAPI Django Main")
|
14 |
+
print("=" * 60)
|
15 |
+
|
16 |
+
# 必須環境変数のチェック
|
17 |
+
required_vars = [
|
18 |
+
'OPENAI_API_KEY',
|
19 |
+
'OPENAI_API_BASE',
|
20 |
+
'MODEL_NAME',
|
21 |
+
'GRADIO_SERVER_NAME',
|
22 |
+
'GRADIO_SERVER_PORT',
|
23 |
+
'GOOGLE_APPLICATION_CREDENTIALS_CONTENT'
|
24 |
+
]
|
25 |
+
|
26 |
+
print("📋 必須環境変数チェック:")
|
27 |
+
all_set = True
|
28 |
+
for var in required_vars:
|
29 |
+
value = os.getenv(var, 'NOT_SET')
|
30 |
+
if value == 'NOT_SET' or value == 'YOUR_VALUE_HERE':
|
31 |
+
print(f" ❌ {var}: 未設定")
|
32 |
+
all_set = False
|
33 |
+
else:
|
34 |
+
# 機密情報はマスク
|
35 |
+
if 'KEY' in var or 'SECRET' in var or 'TOKEN' in var:
|
36 |
+
display_value = value[:8] + '...' if len(value) > 8 else '***'
|
37 |
+
else:
|
38 |
+
display_value = value
|
39 |
+
print(f" ✅ {var}: {display_value}")
|
40 |
+
|
41 |
+
print("\n📦 オプション環境変数:")
|
42 |
+
optional_vars = [
|
43 |
+
'APPSHEET_APPID', 'APPSHEET_KEY', 'ChannelAccessToken',
|
44 |
+
'github_user', 'github_token', 'hf_token'
|
45 |
+
]
|
46 |
+
|
47 |
+
for var in optional_vars:
|
48 |
+
value = os.getenv(var, 'NOT_SET')
|
49 |
+
if value != 'NOT_SET' and value != 'YOUR_VALUE_HERE':
|
50 |
+
print(f" ✅ {var}: 設定済み")
|
51 |
+
else:
|
52 |
+
print(f" ⚠️ {var}: 未設定(オプション)")
|
53 |
+
|
54 |
+
return all_set
|
55 |
+
|
56 |
+
def test_gradio_version():
|
57 |
+
"""Gradio バージョンチェック"""
|
58 |
+
try:
|
59 |
+
import gradio as gr
|
60 |
+
print(f"\n🎨 Gradio バージョン: {gr.__version__}")
|
61 |
+
|
62 |
+
# README.md仕様との比較
|
63 |
+
expected_version = "4.29.0"
|
64 |
+
if gr.__version__ == expected_version:
|
65 |
+
print(f" ✅ README.md仕様と一致: {expected_version}")
|
66 |
+
else:
|
67 |
+
print(f" ⚠️ README.md仕様 ({expected_version}) と異なります")
|
68 |
+
|
69 |
+
return True
|
70 |
+
except ImportError as e:
|
71 |
+
print(f" ❌ Gradio インポートエラー: {e}")
|
72 |
+
return False
|
73 |
+
|
74 |
+
def test_google_cloud_config():
|
75 |
+
"""Google Cloud認証設定テスト"""
|
76 |
+
print("\n☁️ Google Cloud設定:")
|
77 |
+
|
78 |
+
creds_content = os.getenv('GOOGLE_APPLICATION_CREDENTIALS_CONTENT')
|
79 |
+
if creds_content:
|
80 |
+
try:
|
81 |
+
creds_json = json.loads(creds_content)
|
82 |
+
project_id = creds_json.get('project_id', 'NOT_FOUND')
|
83 |
+
client_email = creds_json.get('client_email', 'NOT_FOUND')
|
84 |
+
|
85 |
+
print(f" ✅ プロジェクトID: {project_id}")
|
86 |
+
print(f" ✅ サービスアカウント: {client_email}")
|
87 |
+
return True
|
88 |
+
except json.JSONDecodeError:
|
89 |
+
print(" ❌ 認証情報のJSON形式が無効です")
|
90 |
+
return False
|
91 |
+
else:
|
92 |
+
print(" ❌ Google Cloud認証情報が設定されていません")
|
93 |
+
return False
|
94 |
+
|
95 |
+
def main():
|
96 |
+
"""メインテスト実行"""
|
97 |
+
print("🚀 Docker環境設定検証開始\n")
|
98 |
+
|
99 |
+
env_ok = test_environment_variables()
|
100 |
+
gradio_ok = test_gradio_version()
|
101 |
+
gcp_ok = test_google_cloud_config()
|
102 |
+
|
103 |
+
print("\n" + "=" * 60)
|
104 |
+
print("📊 テスト結果サマリー:")
|
105 |
+
print(f" 環境変数: {'✅ OK' if env_ok else '❌ NG'}")
|
106 |
+
print(f" Gradio: {'✅ OK' if gradio_ok else '❌ NG'}")
|
107 |
+
print(f" Google Cloud: {'✅ OK' if gcp_ok else '❌ NG'}")
|
108 |
+
|
109 |
+
overall_status = all([env_ok, gradio_ok, gcp_ok])
|
110 |
+
if overall_status:
|
111 |
+
print("\n🎉 すべてのテストが通過しました!")
|
112 |
+
print("✨ README.md仕様に準拠したDocker環境が正常に設定されています")
|
113 |
+
else:
|
114 |
+
print("\n⚠️ いくつかの設定に問題があります")
|
115 |
+
print("💡 上記のエラーを修正してから再度テストしてください")
|
116 |
+
|
117 |
+
return 0 if overall_status else 1
|
118 |
+
|
119 |
+
if __name__ == "__main__":
|
120 |
+
sys.exit(main())
|