Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +51 -0
- requirements (1).txt +23 -0
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import openai
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
import logging
|
| 6 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 7 |
+
os.environ["OPENAI_API_KEY"] = os.environ["gptkey"]
|
| 8 |
+
|
| 9 |
+
def gpt_answer(question, dice_1, dice_2, dice_3):
|
| 10 |
+
messages_base = [
|
| 11 |
+
{"role": "system", "content": "請扮演一個具備專業占星學知識,使用占星骰進行占卜的占卜師"}
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
# Creating a prompt with a structured format for the Persona in Traditional Chinese
|
| 15 |
+
prompt_text = f"請根據以下得到的三顆占星骰結果,回答我的問題「{question}」:\n\
|
| 16 |
+
- 行星骰: {dice_1}\n,描述了能量的基礎類型、問題的切入角度、事件的表現形式、人的基本特質。\n\
|
| 17 |
+
- 星座骰: {dice_2}\n,代表了能量的運作模式、問題的展示形態、事件的進行過程、人的行為模式。\n\
|
| 18 |
+
- 宮位骰: {dice_3}\n,展示了能量的影響範圍、問題的推進領域、事件的展示方向、人的目標去處。\n\
|
| 19 |
+
請注意,你的回答需先整合三個骰子的結果根據我的問題進行完整的占卜回答,最後再分別敘述三顆骰子在這個占卜結果中"
|
| 20 |
+
|
| 21 |
+
messages_base.append({"role": "user", "content": prompt_text})
|
| 22 |
+
messages_base.append({"role": "assistant", "content": "以下是本次占卜結果:"})
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
#for _ in range(loop):
|
| 26 |
+
response = client.chat.completions.create(
|
| 27 |
+
model='gpt-4-turbo',
|
| 28 |
+
max_tokens=4096,
|
| 29 |
+
temperature=0,
|
| 30 |
+
messages=messages_base
|
| 31 |
+
)
|
| 32 |
+
completed_text = response.choices[0].message.content
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
return completed_text
|
| 36 |
+
|
| 37 |
+
demo = gr.Interface(
|
| 38 |
+
fn=gpt_answer,
|
| 39 |
+
inputs=[
|
| 40 |
+
gr.Text(label="問題敘述",lines=3),
|
| 41 |
+
gr.Radio(["太陽","月亮","水星","金星","火星","木星","土星","天王星","海王星","冥王星","北交點","南交點"], label="行星骰", info="行星骰子它描述了能量的基礎類型、問題的切入角度、事件的表現形式、人的基本特質"),
|
| 42 |
+
gr.Radio(["白羊座","金牛座","雙子座","巨蟹座","獅子座","處女座","天秤座","天蠍座","射手座","摩羯座","水瓶座","雙魚座"], label="行星骰", info="星座骰子它代表了能量的運作模式、問題的展示形態、事件的進行過程、人的行為模式。"),
|
| 43 |
+
gr.Radio(["一宮","二宮","三宮","四宮","五宮","六宮","七宮","八宮","九宮","十宮","十一宮","十二宮"], label="宮位骰", info="宮位骰子它展示了能量的影響範圍、問題的推進領域、事件的展示方向、人的目標去處。")
|
| 44 |
+
],
|
| 45 |
+
outputs=[
|
| 46 |
+
gr.Text(label="結果解釋",lines=30),
|
| 47 |
+
],
|
| 48 |
+
title="占星骰解釋助手",
|
| 49 |
+
description="根據你的問題,以及占星骰擲出的結果來進行回答",
|
| 50 |
+
allow_flagging="never", )
|
| 51 |
+
demo.launch(share=True)
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
annotated-types==0.6.0
|
| 2 |
+
anthropic==0.25.1
|
| 3 |
+
anyio==4.2.0
|
| 4 |
+
blinker==1.7.0
|
| 5 |
+
certifi==2024.2.2
|
| 6 |
+
click==8.1.7
|
| 7 |
+
distro==1.9.0
|
| 8 |
+
Flask==3.0.2
|
| 9 |
+
h11==0.14.0
|
| 10 |
+
httpcore==1.0.2
|
| 11 |
+
httpx==0.26.0
|
| 12 |
+
idna==3.6
|
| 13 |
+
itsdangerous==2.1.2
|
| 14 |
+
Jinja2==3.1.3
|
| 15 |
+
MarkupSafe==2.1.5
|
| 16 |
+
openai==1.11.1
|
| 17 |
+
pydantic==2.6.1
|
| 18 |
+
pydantic_core==2.16.2
|
| 19 |
+
gradio
|
| 20 |
+
unstructured
|
| 21 |
+
chromadb
|
| 22 |
+
qdrant-client
|
| 23 |
+
textblob
|