Spaces:
Runtime error
Runtime error
VikasQblocks
commited on
Commit
•
ecc07c2
1
Parent(s):
dcf7e45
Fix Client and serving models
Browse files- MonsterAPIClient.py +8 -7
- gradio_app.py +7 -8
MonsterAPIClient.py
CHANGED
@@ -96,9 +96,9 @@ class MClient():
|
|
96 |
'Authorization': 'Bearer ' + self.auth_token}
|
97 |
self.base_url = 'https://api.monsterapi.ai/v1'
|
98 |
self.models_to_data_model = MODELS_TO_DATAMODEL
|
99 |
-
self.mock = os.environ.get('MOCK_Runner', "
|
100 |
|
101 |
-
def get_response(self, model:Literal['falcon-
|
102 |
data: dict):
|
103 |
|
104 |
if model not in self.models_to_data_model:
|
@@ -106,8 +106,9 @@ class MClient():
|
|
106 |
|
107 |
dataModel = self.models_to_data_model[model](**data)
|
108 |
url = f"{self.base_url}/generate/{model}"
|
109 |
-
#url = self.base_url + model
|
110 |
data = dataModel.dict()
|
|
|
|
|
111 |
# convert all values into string
|
112 |
for key, value in data.items():
|
113 |
data[key] = str(value)
|
@@ -123,7 +124,7 @@ class MClient():
|
|
123 |
response.raise_for_status()
|
124 |
return response.json()
|
125 |
|
126 |
-
def wait_and_get_result(self, process_id, timeout=
|
127 |
start_time = time.time()
|
128 |
while True:
|
129 |
elapsed_time = time.time() - start_time
|
@@ -139,12 +140,12 @@ class MClient():
|
|
139 |
else:
|
140 |
if self.mock:
|
141 |
return 100 * "Mock Output!"
|
142 |
-
logger.info(f"Process {process_id} is still running, status is {status['status']}. Waiting
|
143 |
-
time.sleep(0.
|
144 |
|
145 |
|
146 |
if __name__ == '__main__':
|
147 |
client = MClient()
|
148 |
-
response = client.get_response('falcon-7b-instruct', {"prompt": 'How to make a sandwich'})
|
149 |
output = client.wait_and_get_result(response['process_id'])
|
150 |
print(output)
|
|
|
96 |
'Authorization': 'Bearer ' + self.auth_token}
|
97 |
self.base_url = 'https://api.monsterapi.ai/v1'
|
98 |
self.models_to_data_model = MODELS_TO_DATAMODEL
|
99 |
+
self.mock = os.environ.get('MOCK_Runner', "False").lower() == "true"
|
100 |
|
101 |
+
def get_response(self, model:Literal['falcon-7b-instruct', 'falcon-40b-instruct', 'mpt-30B-instruct', 'mpt-7b-instruct', 'openllama-13b-base', 'llama2-7b-chat'],
|
102 |
data: dict):
|
103 |
|
104 |
if model not in self.models_to_data_model:
|
|
|
106 |
|
107 |
dataModel = self.models_to_data_model[model](**data)
|
108 |
url = f"{self.base_url}/generate/{model}"
|
|
|
109 |
data = dataModel.dict()
|
110 |
+
logger.info(f"Calling Monster API with url: {url}, with payload: {data}")
|
111 |
+
|
112 |
# convert all values into string
|
113 |
for key, value in data.items():
|
114 |
data[key] = str(value)
|
|
|
124 |
response.raise_for_status()
|
125 |
return response.json()
|
126 |
|
127 |
+
def wait_and_get_result(self, process_id, timeout=100):
|
128 |
start_time = time.time()
|
129 |
while True:
|
130 |
elapsed_time = time.time() - start_time
|
|
|
140 |
else:
|
141 |
if self.mock:
|
142 |
return 100 * "Mock Output!"
|
143 |
+
logger.info(f"Process {process_id} is still running, status is {status['status']}. Waiting ...")
|
144 |
+
time.sleep(0.01)
|
145 |
|
146 |
|
147 |
if __name__ == '__main__':
|
148 |
client = MClient()
|
149 |
+
response = client.get_response('falcon-7b-instruct', {"prompt": 'How to make a sandwich?'})
|
150 |
output = client.wait_and_get_result(response['process_id'])
|
151 |
print(output)
|
gradio_app.py
CHANGED
@@ -7,8 +7,7 @@ from MonsterAPIClient import MODELS_TO_DATAMODEL
|
|
7 |
client = MClient()
|
8 |
|
9 |
# Available models list
|
10 |
-
|
11 |
-
available_models = list(set(list(MODELS_TO_DATAMODEL.keys())) - set(EXCLUSION_LIST))
|
12 |
|
13 |
def generate_model_output(model: str, input_text: str, temp: float = 0.98) -> str:
|
14 |
"""
|
@@ -28,12 +27,12 @@ def generate_model_output(model: str, input_text: str, temp: float = 0.98) -> st
|
|
28 |
"temp": temp,
|
29 |
})
|
30 |
output = client.wait_and_get_result(response['process_id'])
|
31 |
-
return model, output
|
32 |
except Exception as e:
|
33 |
return model, f"Error occurred: {str(e)}"
|
34 |
|
35 |
def generate_output(selected_models: list, input_text: str, temp: float = 0.98,
|
36 |
-
available_models: list =
|
37 |
"""
|
38 |
Generate outputs from selected models using Monster API.
|
39 |
|
@@ -58,13 +57,13 @@ def generate_output(selected_models: list, input_text: str, temp: float = 0.98,
|
|
58 |
if model not in outputs:
|
59 |
ret_outputs.append("Model not selected!")
|
60 |
else:
|
61 |
-
ret_outputs.append(outputs[model]
|
62 |
|
63 |
-
return ret_outputs
|
64 |
|
65 |
-
output_components = [gr.outputs.Textbox(label=model) for model in
|
66 |
|
67 |
-
checkboxes = gr.inputs.CheckboxGroup(
|
68 |
textbox = gr.inputs.Textbox(label="Input Prompt")
|
69 |
temp = gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.98, label="Temperature", step=0.01)
|
70 |
|
|
|
7 |
client = MClient()
|
8 |
|
9 |
# Available models list
|
10 |
+
MODELS_TO_SERVE = ['llama2-7b-chat','mpt-7b-instruct','falcon-7b-instruct']
|
|
|
11 |
|
12 |
def generate_model_output(model: str, input_text: str, temp: float = 0.98) -> str:
|
13 |
"""
|
|
|
27 |
"temp": temp,
|
28 |
})
|
29 |
output = client.wait_and_get_result(response['process_id'])
|
30 |
+
return model, output['text']
|
31 |
except Exception as e:
|
32 |
return model, f"Error occurred: {str(e)}"
|
33 |
|
34 |
def generate_output(selected_models: list, input_text: str, temp: float = 0.98,
|
35 |
+
available_models: list = MODELS_TO_SERVE) -> list:
|
36 |
"""
|
37 |
Generate outputs from selected models using Monster API.
|
38 |
|
|
|
57 |
if model not in outputs:
|
58 |
ret_outputs.append("Model not selected!")
|
59 |
else:
|
60 |
+
ret_outputs.append(outputs[model])
|
61 |
|
62 |
+
return ret_outputs
|
63 |
|
64 |
+
output_components = [gr.outputs.Textbox(label=model) for model in MODELS_TO_SERVE]
|
65 |
|
66 |
+
checkboxes = gr.inputs.CheckboxGroup(MODELS_TO_SERVE, label="Select models to generate outputs:")
|
67 |
textbox = gr.inputs.Textbox(label="Input Prompt")
|
68 |
temp = gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.98, label="Temperature", step=0.01)
|
69 |
|