mateuo commited on
Commit
ba54825
1 Parent(s): 92c000b

adjust strings data

Browse files
Files changed (2) hide show
  1. handler.py +19 -3
  2. testapi.py +33 -0
handler.py CHANGED
@@ -11,12 +11,28 @@ class EndpointHandler:
11
 
12
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
13
  # Handle the incoming request
14
- input_text = data["inputs"]["text"]
15
- template = data["inputs"]["template"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- # Use the predict function
18
  output = self.predict_NuExtract([input_text], template)
 
19
  return [{"extracted_information": output}]
 
20
 
21
  def predict_NuExtract(self, texts, template, batch_size=1, max_length=10_000, max_new_tokens=4_000):
22
  # Generate prompts based on the template
 
11
 
12
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
13
  # Handle the incoming request
14
+ if isinstance(data, str):
15
+ try:
16
+ data = json.loads(data)
17
+ except json.JSONDecodeError:
18
+ raise ValueError("Input data is not valid JSON.")
19
+
20
+ # Ensure the input data is properly structured
21
+ if isinstance(data, dict) and "inputs" in data:
22
+ input_text = data["inputs"].get("text")
23
+ template = data["inputs"].get("template")
24
+ else:
25
+ raise ValueError("Invalid input format. Expected a dictionary with 'inputs' key.")
26
+
27
+ # Validate that input_text and template are strings
28
+ if not isinstance(input_text, str) or not isinstance(template, str):
29
+ raise ValueError("Both 'text' and 'template' should be strings.")
30
 
31
+ # Run the prediction
32
  output = self.predict_NuExtract([input_text], template)
33
+
34
  return [{"extracted_information": output}]
35
+
36
 
37
  def predict_NuExtract(self, texts, template, batch_size=1, max_length=10_000, max_new_tokens=4_000):
38
  # Generate prompts based on the template
testapi.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ API_URL = "https://t0s30e66o436qkvj.eu-west-1.aws.endpoints.huggingface.cloud"
4
+ headers = {
5
+ "Accept" : "application/json",
6
+ "Authorization": "Bearer ",
7
+ "Content-Type": "application/json"
8
+ }
9
+
10
+ def query(payload):
11
+ response = requests.post(API_URL, headers=headers, json=payload)
12
+ return response.json()
13
+
14
+ output = query({
15
+
16
+ "inputs": {
17
+ "text": "We introduce Mistral 7B, a 7–billion-parameter language model engineered for superior performance and efficiency. Mistral 7B outperforms the best open 13B model (Llama 2) across all evaluated benchmarks, and the best released 34B model (Llama 1) in reasoning, mathematics, and code generation. Our model leverages grouped-query attention (GQA) for faster inference, coupled with sliding window attention (SWA) to effectively handle sequences of arbitrary length with a reduced inference cost. We also provide a model fine-tuned to follow instructions, Mistral 7B – Instruct, that surpasses Llama 2 13B – chat model both on human and automated benchmarks. Our models are released under the Apache 2.0 license. Code: <https://github.com/mistralai/mistral-src> Webpage: <https://mistral.ai/news/announcing-mistral-7b/>",
18
+ "template": {
19
+ "Model": {
20
+ "Name": "",
21
+ "Number of parameters": "",
22
+ "Number of max token": "",
23
+ "Architecture": []
24
+ },
25
+ "Usage": {
26
+ "Use case": [],
27
+ "Licence": ""
28
+ }
29
+ }
30
+ }
31
+
32
+
33
+ })