15
15
![ versions] ( https://img.shields.io/pypi/pyversions/reflex.svg )
16
16
[ ![ Documentaiton] ( https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6 )] ( https://reflex.dev/docs/getting-started/introduction )
17
17
[ ![ Discord] ( https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord )] ( https://discord.gg/T5WSbC2YtQ )
18
+
18
19
</div >
19
20
20
21
---
21
- [ English] ( https://github.com/reflex-dev/reflex/blob/main/README.md ) | [ 简体中文] ( https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_cn/README.md ) | [ 繁體中文] ( https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_tw/README.md ) | [ Türkçe] ( https://github.com/reflex-dev/reflex/blob/main/docs/tr/README.md ) | [ 한국어] ( https://github.com/reflex-dev/reflex/blob/main/docs/kr/README.md ) | [ 日本語] ( https://github.com/reflex-dev/reflex/blob/main/docs/ja/README.md )
22
+
23
+ [ English] ( https://github.com/reflex-dev/reflex/blob/main/README.md ) | [ 简体中文] ( https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_cn/README.md ) | [ 繁體中文] ( https://github.com/reflex-dev/reflex/blob/main/docs/zh/zh_tw/README.md ) | [ Türkçe] ( https://github.com/reflex-dev/reflex/blob/main/docs/tr/README.md ) | [ हिंदी] ( https://github.com/reflex-dev/reflex/blob/main/docs/in/README.md ) | [ Português (Brasil)] ( https://github.com/reflex-dev/reflex/blob/main/docs/pt/pt_br/README.md ) | [ Italiano] ( https://github.com/reflex-dev/reflex/blob/main/docs/it/README.md ) | [ Español] ( https://github.com/reflex-dev/reflex/blob/main/docs/es/README.md ) | [ 한국어] ( https://github.com/reflex-dev/reflex/blob/main/docs/kr/README.md ) | [ 日本語] ( https://github.com/reflex-dev/reflex/blob/main/docs/ja/README.md )
24
+
22
25
---
26
+
27
+ # Reflex
28
+
29
+ Reflex 是一個可以用純 Python 構建全端網頁應用程式的函式庫。
30
+
31
+ 主要特色:
32
+
33
+ * ** 純 Python** - 您可以用 Python 撰寫應用程式的前端和後端,無需學習 Javascript。
34
+ * ** 完全靈活性** - Reflex 易於上手,但也可以擴展到複雜的應用程式。
35
+ * ** 立即部署** - 構建後,只需使用[ 單一指令] ( https://reflex.dev/docs/hosting/deploy-quick-start/ ) 即可部署您的應用程式,或在您自己的伺服器上託管。
36
+ 請參閱我們的[ 架構頁面] ( https://reflex.dev/blog/2024-03-21-reflex-architecture/#the-reflex-architecture ) 了解 Reflex 如何在底層運作。
37
+
23
38
## ⚙️ 安裝
24
39
25
40
開啟一個終端機並且執行 (需要 Python 3.8+):
@@ -70,7 +85,8 @@ reflex run
70
85
import reflex as rx
71
86
import openai
72
87
73
- openai.api_key = " YOUR_API_KEY"
88
+ openai_client = openai.OpenAI()
89
+
74
90
75
91
class State (rx .State ):
76
92
""" 應用程式狀態"""
@@ -86,44 +102,56 @@ class State(rx.State):
86
102
87
103
self .processing, self .complete = True , False
88
104
yield
89
- response = openai.Image.create(prompt = self .prompt, n = 1 , size = " 1024x1024" )
90
- self .image_url = response[" data" ][0 ][" url" ]
105
+ response = openai_client.images.generate(
106
+ prompt = self .prompt, n = 1 , size = " 1024x1024"
107
+ )
108
+ self .image_url = response.data[0 ].url
91
109
self .processing, self .complete = False , True
92
110
93
111
94
112
def index ():
95
113
return rx.center(
96
114
rx.vstack(
97
- rx.heading(" DALL·E" ),
98
- rx.input(placeholder = " Enter a prompt" , on_blur = State.set_prompt),
115
+ rx.heading(" DALL-E" , font_size = " 1.5em" ),
116
+ rx.input(
117
+ placeholder = " Enter a prompt.." ,
118
+ on_blur = State.set_prompt,
119
+ width = " 25em" ,
120
+ ),
99
121
rx.button(
100
- " Generate Image" ,
122
+ " Generate Image" ,
101
123
on_click = State.get_image,
102
- is_loading = State.processing ,
103
- width = " 100% " ,
124
+ width = " 25em " ,
125
+ loading = State.processing
104
126
),
105
127
rx.cond(
106
128
State.complete,
107
- rx.image(
108
- src = State.image_url,
109
- height = " 25em" ,
110
- width = " 25em" ,
111
- )
129
+ rx.image(src = State.image_url, width = " 20em" ),
112
130
),
113
- padding = " 2em" ,
114
- shadow = " lg" ,
115
- border_radius = " lg" ,
131
+ align = " center" ,
116
132
),
117
133
width = " 100%" ,
118
134
height = " 100vh" ,
119
135
)
120
136
121
137
# 把狀態跟頁面添加到應用程式。
122
138
app = rx.App()
123
- app.add_page(index, title = " reflex :DALL· E" )
139
+ app.add_page(index, title = " Reflex :DALL- E" )
124
140
```
125
141
142
+
143
+
144
+
145
+
146
+
147
+
126
148
## 讓我們來拆解一下。
149
+
150
+ <div align =" center " >
151
+ <img src =" docs/images/dalle_colored_code_example.png " alt =" Explaining the differences between backend and frontend parts of the DALL-E app. " width =" 900 " />
152
+ </div >
153
+
154
+
127
155
### ** Reflex 使用者介面**
128
156
129
157
讓我們從使用介面開始。
@@ -150,8 +178,9 @@ class State(rx.State):
150
178
""" 應用程式狀態"""
151
179
prompt = " "
152
180
image_url = " "
153
- image_processing = False
154
- image_made = False
181
+ processing = False
182
+ complete = False
183
+
155
184
```
156
185
157
186
應用程式狀態定義了應用程式中所有可以更改的變數及變更他們的函式 (稱為 vars)。
@@ -168,8 +197,10 @@ def get_image(self):
168
197
169
198
self .processing, self .complete = True , False
170
199
yield
171
- response = openai.Image.create(prompt = self .prompt, n = 1 , size = " 1024x1024" )
172
- self .image_url = response[" data" ][0 ][" url" ]
200
+ response = openai_client.images.generate(
201
+ prompt = self .prompt, n = 1 , size = " 1024x1024"
202
+ )
203
+ self .image_url = response.data[0 ].url
173
204
self .processing, self .complete = False , True
174
205
```
175
206
@@ -199,34 +230,35 @@ app.add_page(index, title="DALL-E")
199
230
200
231
<div align =" center " >
201
232
202
- 📑 [ Docs] ( https://reflex.dev/docs/getting-started/introduction )   ; |   ; 🗞️ [ Blog] ( https://reflex.dev/blog )   ; |   ; 📱 [ Component Library] ( https://reflex.dev/docs/library )   ; |   ; 🖼️ [ Gallery] ( https://reflex.dev/docs/gallery )   ; |   ; 🛸 [ Deployment] ( https://reflex.dev/docs/hosting/deploy )   ;
233
+ 📑 [ Docs] ( https://reflex.dev/docs/getting-started/introduction )   ; |   ; 🗞️ [ Blog] ( https://reflex.dev/blog )   ; |   ; 📱 [ Component Library] ( https://reflex.dev/docs/library )   ; |   ; 🖼️ [ Gallery] ( https://reflex.dev/docs/gallery )   ; |   ; 🛸 [ Deployment] ( https://reflex.dev/docs/hosting/deploy-quick-start )   ;
203
234
204
235
</div >
205
236
206
237
207
238
208
- ## ✅ Reflex 狀態
239
+ ## ✅ 產品狀態
209
240
210
- Reflex 於 2022 年 12 月推出,當時名為 Pynecone。
241
+ Reflex 在 2022 年 12 月以 Pynecone 的名字推出 。
211
242
212
- 截至 2023 年 7 月,我們處於 ** Public Beta** 階段。
213
-
214
- - :white_check_mark : ** Public Alpha** : 任何人都可以安裝與使用 Reflex,或許包含問題, 但我們正在積極的解決他們。
215
- - :large_orange_diamond : ** Public Beta** : 對於不涉及商業目的使用情境來說足夠穩定。
216
- - ** Public Hosting Beta** : _ Optionally_ , 部屬跟託管你的 Reflex!
217
- - ** Public** : 這版本的 Reflex 是可用於軟體產品的。
243
+ 截至 2024 年 2 月,我們的託管服務已進入 alpha 階段!在此期間,任何人都可以免費部署他們的應用程式。請參閱我們的[ 產品地圖] ( https://github.com/reflex-dev/reflex/issues/2727 ) 了解未來的計劃。
218
244
219
245
Reflex 每周都有新功能和釋出新版本! 確保你按下 :star : 和 :eyes : watch 這個 repository 來確保知道最新資訊。
220
246
221
247
## 貢獻
222
248
223
- 我們歡迎任何大小的貢獻,以下是幾個好的方法來加入 Reflex 社群。
249
+ 我們歡迎任何大小的貢獻,以下是一些加入 Reflex 社群的好方法。
250
+
251
+ - ** 加入我們的 Discord** : 我們的 [ Discord] ( https://discord.gg/T5WSbC2YtQ ) 是獲取 Reflex 專案幫助和討論如何貢獻的最佳地方。
252
+ - ** GitHub Discussions** : 這是一個討論您想新增的功能或對於一些困惑/需要澄清事項的好方法。
253
+ - ** GitHub Issues** : 在 [ Issues] ( https://github.com/reflex-dev/reflex/issues ) 頁面報告錯誤是一個絕佳的方式。此外,您也可以嘗試解決現有 Issue 並提交 PR。
254
+
255
+ 我們積極尋找貢獻者,不論您的技能水平或經驗如何。要貢獻,請查看 [ CONTIBUTING.md] ( https://github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md )
224
256
225
- - ** 加入我們的 Discord** : 我們的 [ Discord] ( https://discord.gg/T5WSbC2YtQ ) 是幫助你加入 Reflex 專案和討論或貢獻最棒的地方。
226
- - ** GitHub Discussions** : 一個來討論你想要添加的功能或是需要澄清的事情的好地方。
227
- - ** GitHub Issues** : 報告錯誤的絕佳地方,另外你可以試著解決一些 issue 和送出 PR。
228
257
229
- 我們正在積極尋找貢獻者,無關你的技能水平或經驗。
258
+ ## 感謝所有貢獻者:
259
+ <a href =" https://github.com/reflex-dev/reflex/graphs/contributors " >
260
+ <img src =" https://contrib.rocks/image?repo=reflex-dev/reflex " />
261
+ </a >
230
262
231
263
## 授權
232
264
0 commit comments