Spaces:
Runtime error
Runtime error
Ugly thins to get ip
Browse files
app.py
CHANGED
|
@@ -16,6 +16,20 @@ def start_app()-> Tuple[bool, bool, bool]:
|
|
| 16 |
gr.update(visible=False), # start_button visible
|
| 17 |
)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def change_vote( _id:str, backdown: bool,) -> Tuple[bool, bool]:
|
| 20 |
print(backdown, _id)
|
| 21 |
response = requests.post(url + "/v2/backdownvote", json={"backdown": backdown, "_id": _id})
|
|
@@ -25,7 +39,7 @@ def change_vote( _id:str, backdown: bool,) -> Tuple[bool, bool]:
|
|
| 25 |
)
|
| 26 |
|
| 27 |
def record_vote(prompt: str, left_chat: List, right_chat: List,
|
| 28 |
-
left_model: str, right_model: str, energy, moreConsuming, vote_type: int ) -> Tuple[str, bool, bool, bool, bool, bool]:
|
| 29 |
"""Record a vote for either the left or right model"""
|
| 30 |
vote_message = "Is a tie!"
|
| 31 |
if vote_type == 0:
|
|
@@ -36,6 +50,7 @@ def record_vote(prompt: str, left_chat: List, right_chat: List,
|
|
| 36 |
response = requests.post(url + "/v2/vote", json={"vote": vote_type, "prompt": prompt,
|
| 37 |
"left_chat": left_chat, "right_chat": right_chat,
|
| 38 |
"left_model": left_model, "right_model": right_model,
|
|
|
|
| 39 |
})
|
| 40 |
changeVisible = False
|
| 41 |
jsonResponse = response.json()
|
|
@@ -175,19 +190,19 @@ with gr.Blocks(css="footer{display:none !important}") as demo:
|
|
| 175 |
|
| 176 |
|
| 177 |
buttons[0].click(
|
| 178 |
-
|
| 179 |
inputs=[textbox, chatbot[0], chatbot[1], left_model, right_model, gr.State(value=False), moreConsuming],
|
| 180 |
outputs=[result,buttons[0], buttons[1], tievote_btn, model_names_row, backdown_row, _id]
|
| 181 |
)
|
| 182 |
|
| 183 |
buttons[1].click(
|
| 184 |
-
|
| 185 |
inputs=[textbox, chatbot[0], chatbot[1], left_model, right_model, gr.State(value=False), moreConsuming],
|
| 186 |
outputs=[result,buttons[0], buttons[1], tievote_btn, model_names_row, backdown_row, _id]
|
| 187 |
)
|
| 188 |
|
| 189 |
tievote_btn.click(
|
| 190 |
-
|
| 191 |
inputs=[textbox, chatbot[0], chatbot[1], left_model, right_model, gr.State(value=False), moreConsuming],
|
| 192 |
outputs=[result,buttons[0], buttons[1], tievote_btn, model_names_row, backdown_row, _id]
|
| 193 |
)
|
|
@@ -242,5 +257,5 @@ Este space es parte de un proyecto de investigaci贸n para estudiar c贸mo el cono
|
|
| 242 |
|
| 243 |
if __name__ == "__main__":
|
| 244 |
gr.set_static_paths(paths=[os.path.join(os.path.dirname(__file__), "static")])
|
| 245 |
-
demo.launch(show_api=False
|
| 246 |
|
|
|
|
| 16 |
gr.update(visible=False), # start_button visible
|
| 17 |
)
|
| 18 |
|
| 19 |
+
|
| 20 |
+
#Dont ask, best way to get the request param
|
| 21 |
+
def record_vote_0(prompt: str, left_chat: List, right_chat: List,
|
| 22 |
+
left_model: str, right_model: str, energy, moreConsuming, request: gr.Request) -> Tuple[str, bool, bool, bool, bool, bool]:
|
| 23 |
+
return record_vote(prompt, left_chat, right_chat, left_model, right_model, energy, moreConsuming, request, 0)
|
| 24 |
+
|
| 25 |
+
def record_vote_1(prompt: str, left_chat: List, right_chat: List,
|
| 26 |
+
left_model: str, right_model: str, energy, moreConsuming, request: gr.Request) -> Tuple[str, bool, bool, bool, bool, bool]:
|
| 27 |
+
return record_vote(prompt, left_chat, right_chat, left_model, right_model, energy, moreConsuming, request, 1)
|
| 28 |
+
|
| 29 |
+
def record_vote_2(prompt: str, left_chat: List, right_chat: List,
|
| 30 |
+
left_model: str, right_model: str, energy, moreConsuming, request: gr.Request) -> Tuple[str, bool, bool, bool, bool, bool]:
|
| 31 |
+
return record_vote(prompt, left_chat, right_chat, left_model, right_model, energy, moreConsuming, request, 2)
|
| 32 |
+
|
| 33 |
def change_vote( _id:str, backdown: bool,) -> Tuple[bool, bool]:
|
| 34 |
print(backdown, _id)
|
| 35 |
response = requests.post(url + "/v2/backdownvote", json={"backdown": backdown, "_id": _id})
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
def record_vote(prompt: str, left_chat: List, right_chat: List,
|
| 42 |
+
left_model: str, right_model: str, energy, moreConsuming, request: gr.Request, vote_type: int ) -> Tuple[str, bool, bool, bool, bool, bool]:
|
| 43 |
"""Record a vote for either the left or right model"""
|
| 44 |
vote_message = "Is a tie!"
|
| 45 |
if vote_type == 0:
|
|
|
|
| 50 |
response = requests.post(url + "/v2/vote", json={"vote": vote_type, "prompt": prompt,
|
| 51 |
"left_chat": left_chat, "right_chat": right_chat,
|
| 52 |
"left_model": left_model, "right_model": right_model,
|
| 53 |
+
"ip": request.client.host
|
| 54 |
})
|
| 55 |
changeVisible = False
|
| 56 |
jsonResponse = response.json()
|
|
|
|
| 190 |
|
| 191 |
|
| 192 |
buttons[0].click(
|
| 193 |
+
record_vote_0,
|
| 194 |
inputs=[textbox, chatbot[0], chatbot[1], left_model, right_model, gr.State(value=False), moreConsuming],
|
| 195 |
outputs=[result,buttons[0], buttons[1], tievote_btn, model_names_row, backdown_row, _id]
|
| 196 |
)
|
| 197 |
|
| 198 |
buttons[1].click(
|
| 199 |
+
record_vote_1,
|
| 200 |
inputs=[textbox, chatbot[0], chatbot[1], left_model, right_model, gr.State(value=False), moreConsuming],
|
| 201 |
outputs=[result,buttons[0], buttons[1], tievote_btn, model_names_row, backdown_row, _id]
|
| 202 |
)
|
| 203 |
|
| 204 |
tievote_btn.click(
|
| 205 |
+
record_vote_2,
|
| 206 |
inputs=[textbox, chatbot[0], chatbot[1], left_model, right_model, gr.State(value=False), moreConsuming],
|
| 207 |
outputs=[result,buttons[0], buttons[1], tievote_btn, model_names_row, backdown_row, _id]
|
| 208 |
)
|
|
|
|
| 257 |
|
| 258 |
if __name__ == "__main__":
|
| 259 |
gr.set_static_paths(paths=[os.path.join(os.path.dirname(__file__), "static")])
|
| 260 |
+
demo.launch(show_api=False)
|
| 261 |
|