Spaces:
Sleeping
Sleeping
Rename the style control argument
Browse files- html/index.html +6 -6
- src/app.lua +5 -5
html/index.html
CHANGED
@@ -30,10 +30,10 @@
|
|
30 |
</el-select>
|
31 |
</el-form-item>
|
32 |
<el-form-item class="params-item">
|
33 |
-
<el-input v-model="form.
|
34 |
</el-form-item>
|
35 |
<el-form-item class="params-end">
|
36 |
-
<el-button class="req-btn" type="primary" @click="request" :disabled="!image || !form.
|
37 |
</el-form-item>
|
38 |
</el-form>
|
39 |
<el-steps :active="statusId" finish-status="success" align-center>
|
@@ -87,7 +87,7 @@
|
|
87 |
image: undefined,
|
88 |
form: {
|
89 |
lang: 'en',
|
90 |
-
|
91 |
},
|
92 |
lastForm: {},
|
93 |
statusId: -1,
|
@@ -108,7 +108,7 @@
|
|
108 |
imageUrl() {
|
109 |
return URL.createObjectURL(this.image)
|
110 |
},
|
111 |
-
|
112 |
const appWidth = this.clientWidth > 640 ? 640 - 16 : this.clientWidth - 16
|
113 |
return {
|
114 |
width: appWidth - 180 + 'px'
|
@@ -124,9 +124,9 @@
|
|
124 |
watch: {
|
125 |
'form.lang': function(value) {
|
126 |
if (value === 'en') {
|
127 |
-
this.form.
|
128 |
} else if (value === 'zh') {
|
129 |
-
this.form.
|
130 |
}
|
131 |
}
|
132 |
},
|
|
|
30 |
</el-select>
|
31 |
</el-form-item>
|
32 |
<el-form-item class="params-item">
|
33 |
+
<el-input v-model="form.style" placeholder="Style" maxlength="32" :style="styleInput" :disabled="working" show-word-limit />
|
34 |
</el-form-item>
|
35 |
<el-form-item class="params-end">
|
36 |
+
<el-button class="req-btn" type="primary" @click="request" :disabled="!image || !form.style.trim() || working">{{ reqBtnText }}</el-button>
|
37 |
</el-form-item>
|
38 |
</el-form>
|
39 |
<el-steps :active="statusId" finish-status="success" align-center>
|
|
|
87 |
image: undefined,
|
88 |
form: {
|
89 |
lang: 'en',
|
90 |
+
style: 'Emily Dickinson'
|
91 |
},
|
92 |
lastForm: {},
|
93 |
statusId: -1,
|
|
|
108 |
imageUrl() {
|
109 |
return URL.createObjectURL(this.image)
|
110 |
},
|
111 |
+
styleInput() {
|
112 |
const appWidth = this.clientWidth > 640 ? 640 - 16 : this.clientWidth - 16
|
113 |
return {
|
114 |
width: appWidth - 180 + 'px'
|
|
|
124 |
watch: {
|
125 |
'form.lang': function(value) {
|
126 |
if (value === 'en') {
|
127 |
+
this.form.style = 'Emily Dickinson'
|
128 |
} else if (value === 'zh') {
|
129 |
+
this.form.style = '海子'
|
130 |
}
|
131 |
}
|
132 |
},
|
src/app.lua
CHANGED
@@ -74,27 +74,27 @@ function gemma_loop(ws)
|
|
74 |
if tp == "text" then
|
75 |
local msg = assert(require("cjson.safe").decode(data))
|
76 |
if msg.op == "create" then
|
77 |
-
assert(msg.lang and msg.
|
78 |
local prompt = assert(prompts[msg.lang], string.format("create error: invalid `lang` %s", tostring(msg.lang)))
|
79 |
assert(send_resp(ws, {op = "status", id = 0}))
|
80 |
image = assert(embed_image(msg.image))
|
81 |
assert(send_resp(ws, {op = "status", id = 1}))
|
82 |
session:reset()
|
83 |
-
assert(session(image, string.format(prompt, msg.
|
84 |
retry_state = assert(session:dumps())
|
85 |
assert(send_resp(ws, {op = "status", id = 2}))
|
86 |
assert(session("<end_of_turn>\n<start_of_turn>model\n", stream_fn))
|
87 |
elseif msg.op == "retry" then
|
88 |
-
if not msg.lang and not msg.
|
89 |
assert(retry_state, "retry error: there is no existing request")
|
90 |
assert(session:loads(retry_state))
|
91 |
else
|
92 |
assert(image, "retry error: there is no existing image")
|
93 |
-
assert(msg.lang and msg.
|
94 |
local prompt = assert(prompts[msg.lang], string.format("retry error: invalid `lang` %s", tostring(msg.lang)))
|
95 |
assert(send_resp(ws, {op = "status", id = 1}))
|
96 |
session:reset()
|
97 |
-
assert(session(image, string.format(prompt, msg.
|
98 |
retry_state = assert(session:dumps())
|
99 |
end
|
100 |
assert(send_resp(ws, {op = "status", id = 2}))
|
|
|
74 |
if tp == "text" then
|
75 |
local msg = assert(require("cjson.safe").decode(data))
|
76 |
if msg.op == "create" then
|
77 |
+
assert(msg.lang and msg.style, "create error: both `lang` and `style` MUST be set")
|
78 |
local prompt = assert(prompts[msg.lang], string.format("create error: invalid `lang` %s", tostring(msg.lang)))
|
79 |
assert(send_resp(ws, {op = "status", id = 0}))
|
80 |
image = assert(embed_image(msg.image))
|
81 |
assert(send_resp(ws, {op = "status", id = 1}))
|
82 |
session:reset()
|
83 |
+
assert(session(image, string.format(prompt, msg.style), prefill_fn))
|
84 |
retry_state = assert(session:dumps())
|
85 |
assert(send_resp(ws, {op = "status", id = 2}))
|
86 |
assert(session("<end_of_turn>\n<start_of_turn>model\n", stream_fn))
|
87 |
elseif msg.op == "retry" then
|
88 |
+
if not msg.lang and not msg.style then
|
89 |
assert(retry_state, "retry error: there is no existing request")
|
90 |
assert(session:loads(retry_state))
|
91 |
else
|
92 |
assert(image, "retry error: there is no existing image")
|
93 |
+
assert(msg.lang and msg.style, "retry error: both `lang` and `style` MUST be set")
|
94 |
local prompt = assert(prompts[msg.lang], string.format("retry error: invalid `lang` %s", tostring(msg.lang)))
|
95 |
assert(send_resp(ws, {op = "status", id = 1}))
|
96 |
session:reset()
|
97 |
+
assert(session(image, string.format(prompt, msg.style), prefill_fn))
|
98 |
retry_state = assert(session:dumps())
|
99 |
end
|
100 |
assert(send_resp(ws, {op = "status", id = 2}))
|