Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -82,7 +82,50 @@ def load_demo_refresh_model_list(request: gr.Request):
|
|
82 |
return state, dropdown_update
|
83 |
|
84 |
|
85 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
with open(get_conv_log_filename(), "a") as fout:
|
87 |
data = {
|
88 |
"tstamp": round(time.time(), 4),
|
@@ -504,6 +547,11 @@ def build_demo(embed_mode):
|
|
504 |
[state, chatbot] + btn_list,
|
505 |
)
|
506 |
|
|
|
|
|
|
|
|
|
|
|
507 |
if args.model_list_mode == "once":
|
508 |
demo.load(
|
509 |
load_demo,
|
|
|
82 |
return state, dropdown_update
|
83 |
|
84 |
|
85 |
+
def vote_dummy_fn(tmp, index_state, data: gr.LikeData):
|
86 |
+
value_new = data.value
|
87 |
+
index_new = data.index
|
88 |
+
if len(index_state) == 0 :
|
89 |
+
index_state.append(index_new)
|
90 |
+
else:
|
91 |
+
if index_new in index_state:
|
92 |
+
gr.Warning('Your feedback is already saved.')
|
93 |
+
return index_state
|
94 |
+
else:
|
95 |
+
index_state.append(index_new)
|
96 |
+
|
97 |
+
#return str(data.value) + ";" + str(data.index)+";"+ str(data.liked)+";"+str(index_state), index_state
|
98 |
+
return index_state
|
99 |
+
|
100 |
+
#chatbot.like(vote_last_response, [model_selector, index_state], [index_state])
|
101 |
+
def vote_last_response(chatbot, model_selector, index_state, request: gr.Request, data: gr.LikeData):
|
102 |
+
|
103 |
+
vote_type = "upvote" if data.liked else "downvote"
|
104 |
+
vote_value = data.value
|
105 |
+
vote_index = data.index
|
106 |
+
if len(index_state) == 0 :
|
107 |
+
index_state.append(vote_index)
|
108 |
+
else:
|
109 |
+
if vote_index in index_state:
|
110 |
+
gr.Warning('Your feedback is already saved.')
|
111 |
+
return index_state
|
112 |
+
else:
|
113 |
+
index_state.append(index_new)
|
114 |
+
|
115 |
+
with open(get_conv_log_filename(), "a") as fout:
|
116 |
+
data = {
|
117 |
+
"tstamp": round(time.time(), 4),
|
118 |
+
"type": vote_type,
|
119 |
+
"model": model_selector,
|
120 |
+
"state": chatbot[vote_index[0]],
|
121 |
+
"ip": request.client.host,
|
122 |
+
}
|
123 |
+
logger.info(f"^^^^^ data is - {data}")
|
124 |
+
fout.write(json.dumps(data) + "\n")
|
125 |
+
|
126 |
+
return index_state
|
127 |
+
|
128 |
+
def vote_last_response_old(state, vote_type, model_selector, request: gr.Request):
|
129 |
with open(get_conv_log_filename(), "a") as fout:
|
130 |
data = {
|
131 |
"tstamp": round(time.time(), 4),
|
|
|
547 |
[state, chatbot] + btn_list,
|
548 |
)
|
549 |
|
550 |
+
# For adding voting option to chatbot
|
551 |
+
chatbot.like(vote_last_response, [chatbot, model_selector, index_state], [index_state])
|
552 |
+
#def vote_last_response(chatbot, model_selector, index_state, request: gr.Request, data: gr.LikeData):
|
553 |
+
#state, model_selector, request: gr.Request
|
554 |
+
|
555 |
if args.model_list_mode == "once":
|
556 |
demo.load(
|
557 |
load_demo,
|