ADD: 公告

This commit is contained in:
兰志宏
2025-03-03 18:28:11 +08:00
parent cc86523b6a
commit c967531e95
6 changed files with 40 additions and 14 deletions

7
.env
View File

@@ -1,3 +1,4 @@
GEMINI_API_KEY= API_KEY=
GEMINI_API_URL= API_URL=
GEMINI_API_MODEL= API_MODEL=
ANNOUNCEMENT_TEXT=

View File

@@ -14,9 +14,9 @@
docker run -d \ docker run -d \
--name stock-scanner \ --name stock-scanner \
-p 8888:8888 \ -p 8888:8888 \
-e GEMINI_API_KEY=替换为你的key \ -e API_KEY=替换为你的key \
-e GEMINI_API_URL=替换为你的api地址 \ -e API_URL=替换为你的api地址 \
-e GEMINI_API_MODEL=替换为你的模型 \ -e API_MODEL=替换为你的模型 \
lanzhihong/stock-scanner:latest lanzhihong/stock-scanner:latest
``` ```
默认8888端口部署完成后访问 http://127.0.0.1:8888 即可使用。 默认8888端口部署完成后访问 http://127.0.0.1:8888 即可使用。

View File

@@ -4,9 +4,11 @@ services:
stock-analyzer: stock-analyzer:
build: . build: .
ports: ports:
- "50684:8080" - "8888:8888"
environment: environment:
- GEMINI_API_KEY=${GEMINI_API_KEY} - API_KEY=${API_KEY}
- API_URL=${API_URL}
- API_MODEL=${API_MODEL}
volumes: volumes:
- .:/app - .:/app
restart: unless-stopped restart: unless-stopped

View File

@@ -18,8 +18,8 @@ class StockAnalyzer:
load_dotenv() load_dotenv()
# 设置 Gemini API # 设置 Gemini API
self.gemini_api_url = os.getenv('GEMINI_API_URL') self.API_URL = os.getenv('API_URL')
self.gemini_api_key = os.getenv('GEMINI_API_KEY') self.API_KEY = os.getenv('API_KEY')
# 配置参数 # 配置参数
self.params = { self.params = {
@@ -243,17 +243,17 @@ class StockAnalyzer:
""" """
headers = { headers = {
"Authorization": f"Bearer {self.gemini_api_key}", "Authorization": f"Bearer {self.API_KEY}",
"Content-Type": "application/json" "Content-Type": "application/json"
} }
data = { data = {
"model": os.getenv('GEMINI_API_MODEL'), "model": os.getenv('API_MODEL'),
"messages": [{"role": "user", "content": prompt}] "messages": [{"role": "user", "content": prompt}]
} }
response = requests.post( response = requests.post(
f"{self.gemini_api_url}/v1/chat/completions", f"{self.API_URL}/v1/chat/completions",
headers=headers, headers=headers,
json=data, json=data,
timeout=30 timeout=30

View File

@@ -10,6 +10,26 @@
<div class="container mx-auto px-4 py-8"> <div class="container mx-auto px-4 py-8">
<h1 class="text-3xl font-bold mb-8 text-center">股票分析系统</h1> <h1 class="text-3xl font-bold mb-8 text-center">股票分析系统</h1>
<!-- 添加公告栏 -->
{% if announcement %}
<div class="max-w-4xl mx-auto mb-8">
<div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-blue-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<p class="text-sm text-blue-700">
{{ announcement }}
</p>
</div>
</div>
</div>
</div>
{% endif %}
<div class="max-w-4xl mx-auto"> <!-- 将 max-w-2xl 改为 max-w-4xl --> <div class="max-w-4xl mx-auto"> <!-- 将 max-w-2xl 改为 max-w-4xl -->
<!-- 批量分析 --> <!-- 批量分析 -->
<div class="bg-white p-6 rounded-lg shadow-md"> <div class="bg-white p-6 rounded-lg shadow-md">

View File

@@ -5,6 +5,7 @@ import threading
import logging import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
import traceback import traceback
import os
app = Flask(__name__) app = Flask(__name__)
analyzer = StockAnalyzer() analyzer = StockAnalyzer()
@@ -20,7 +21,9 @@ app.logger.addHandler(handler)
@app.route('/') @app.route('/')
def index(): def index():
return render_template('index.html') # 如果环境变量不存在或为空,返回 None
announcement = os.getenv('ANNOUNCEMENT_TEXT') or None
return render_template('index.html', announcement=announcement)
@app.route('/analyze', methods=['POST']) @app.route('/analyze', methods=['POST'])
def analyze(): def analyze():