Spaces:
Running
on
Zero
Running
on
Zero
test
Browse files- mysite/asgi.py +46 -0
- requirements.txt +2 -0
mysite/asgi.py
CHANGED
@@ -620,6 +620,52 @@ demo4 = gr.ChatInterface(
|
|
620 |
)
|
621 |
|
622 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
623 |
def do_something_to_file(file_path):
|
624 |
# ファイルに対して実行する処理をここに記述
|
625 |
with open(file_path, "r") as f:
|
|
|
620 |
)
|
621 |
|
622 |
|
623 |
+
# ログ設定
|
624 |
+
logging.basicConfig(level=logging.INFO)
|
625 |
+
logger = logging.getLogger(__name__)
|
626 |
+
|
627 |
+
CHANNEL_ID = os.getenv('CHANNEL_ID')
|
628 |
+
CHANNEL_SECRET = os.getenv('CHANNEL_SECRET')
|
629 |
+
CHANNEL_ACCESS_TOKEN = os.getenv('CHANNEL_ACCESS_TOKEN')
|
630 |
+
WEBHOOK_URL = "https://api.coze.com/adapter/line/webhook/7372538698808246290"
|
631 |
+
|
632 |
+
@app.post("/webhook")
|
633 |
+
async def webhook(request: Request):
|
634 |
+
try:
|
635 |
+
# 受信したデータとヘッダーを取得
|
636 |
+
received_data = await request.json()
|
637 |
+
received_headers = request.headers
|
638 |
+
|
639 |
+
# ログに記録
|
640 |
+
logger.info('Received Data: %s', received_data)
|
641 |
+
logger.info('Received Headers: %s', received_headers)
|
642 |
+
|
643 |
+
# 必要なヘッダー情報を抽出
|
644 |
+
line_signature = received_headers.get('x-line-signature')
|
645 |
+
if not line_signature:
|
646 |
+
raise HTTPException(status_code=400, detail="X-Line-Signature header is missing.")
|
647 |
+
|
648 |
+
# 送信先のURLとヘッダー
|
649 |
+
headers = {
|
650 |
+
'Content-Type': 'application/json',
|
651 |
+
'X-Line-Signature': line_signature,
|
652 |
+
'Authorization': f'Bearer {CHANNEL_ACCESS_TOKEN}'
|
653 |
+
}
|
654 |
+
|
655 |
+
# データを転送
|
656 |
+
response = requests.post(WEBHOOK_URL, json=received_data, headers=headers)
|
657 |
+
|
658 |
+
# レスポンスをログに記録
|
659 |
+
logger.info('Response Code: %s', response.status_code)
|
660 |
+
logger.info('Response Content: %s', response.text)
|
661 |
+
|
662 |
+
return {"status": "success"}, response.status_code
|
663 |
+
|
664 |
+
except Exception as e:
|
665 |
+
logger.error("Error: %s", str(e))
|
666 |
+
raise HTTPException(status_code=500, detail=str(e))
|
667 |
+
|
668 |
+
|
669 |
def do_something_to_file(file_path):
|
670 |
# ファイルに対して実行する処理をここに記述
|
671 |
with open(file_path, "r") as f:
|
requirements.txt
CHANGED
@@ -41,3 +41,5 @@ typing-extensions ; python_version >= "3.10" and python_version < "4.0"
|
|
41 |
tzdata==2024.1 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32"
|
42 |
uvloop==0.19.0 ; python_version >= "3.10" and python_version < "4.0" and sys_platform != "win32"
|
43 |
whitenoise==6.6.0 ; python_version >= "3.10" and python_version < "4.0"
|
|
|
|
|
|
41 |
tzdata==2024.1 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32"
|
42 |
uvloop==0.19.0 ; python_version >= "3.10" and python_version < "4.0" and sys_platform != "win32"
|
43 |
whitenoise==6.6.0 ; python_version >= "3.10" and python_version < "4.0"
|
44 |
+
llamafactory
|
45 |
+
gradio=4.31.5
|