Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,22 @@ import io
|
|
5 |
from typing import Any, Tuple
|
6 |
import os
|
7 |
|
|
|
8 |
class Client:
|
9 |
def __init__(self, server_url: str):
|
10 |
self.server_url = server_url
|
11 |
|
12 |
def send_request(self, task_name: str, model_name: str, text: str, normalization_type: str) -> Tuple[Any, str]:
|
13 |
-
response = requests.post(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
if response.status_code == 200:
|
15 |
response_data = response.json()
|
16 |
img_data = bytes.fromhex(response_data["image"])
|
@@ -31,7 +41,7 @@ with gr.Blocks() as demo:
|
|
31 |
choices=[
|
32 |
"facebook/opt-1.3b",
|
33 |
"facebook/opt-2.7b",
|
34 |
-
"microsoft/Phi-3-mini-128k-instruct"
|
35 |
],
|
36 |
value="facebook/opt-1.3b",
|
37 |
label="Select Model"
|
@@ -75,7 +85,13 @@ with gr.Blocks() as demo:
|
|
75 |
if task_name == "Tokenwise loss without i-th layer":
|
76 |
return "token-wise"
|
77 |
|
|
|
|
|
|
|
|
|
|
|
78 |
task_selector.select(set_default, [task_selector], [normalization_selector])
|
|
|
79 |
submit.click(
|
80 |
fn=update_output,
|
81 |
inputs=[task_selector, model_selector, text_message, normalization_selector, log_output],
|
|
|
5 |
from typing import Any, Tuple
|
6 |
import os
|
7 |
|
8 |
+
|
9 |
class Client:
|
10 |
def __init__(self, server_url: str):
|
11 |
self.server_url = server_url
|
12 |
|
13 |
def send_request(self, task_name: str, model_name: str, text: str, normalization_type: str) -> Tuple[Any, str]:
|
14 |
+
response = requests.post(
|
15 |
+
self.server_url,
|
16 |
+
json={
|
17 |
+
"task_name": task_name,
|
18 |
+
"model_name": model_name,
|
19 |
+
"text": text,
|
20 |
+
"normalization_type": normalization_type
|
21 |
+
},
|
22 |
+
timeout=60
|
23 |
+
)
|
24 |
if response.status_code == 200:
|
25 |
response_data = response.json()
|
26 |
img_data = bytes.fromhex(response_data["image"])
|
|
|
41 |
choices=[
|
42 |
"facebook/opt-1.3b",
|
43 |
"facebook/opt-2.7b",
|
44 |
+
# "microsoft/Phi-3-mini-128k-instruct"
|
45 |
],
|
46 |
value="facebook/opt-1.3b",
|
47 |
label="Select Model"
|
|
|
85 |
if task_name == "Tokenwise loss without i-th layer":
|
86 |
return "token-wise"
|
87 |
|
88 |
+
def check_normalization(task_name: str, normalization_name) -> Tuple[str, str]:
|
89 |
+
if task_name == "Contextualization mesurment" and normalization_name == "token-wise":
|
90 |
+
return ("global", "\nALERT: Cannot apply token-wise normalization to one sentence, setting global normalization\n")
|
91 |
+
return (normalization_name, "")
|
92 |
+
|
93 |
task_selector.select(set_default, [task_selector], [normalization_selector])
|
94 |
+
normalization_selector.select(check_normalization, [task_selector, normalization_selector], [normalization_selector, log_output])
|
95 |
submit.click(
|
96 |
fn=update_output,
|
97 |
inputs=[task_selector, model_selector, text_message, normalization_selector, log_output],
|