janasumit2911 commited on
Commit
38697c4
·
verified ·
1 Parent(s): f12c13d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -8,14 +8,14 @@ import json
8
  # Load your custom NER model
9
  nlp_ner = spacy.load("ner_model_v1")
10
 
11
- def send_results_to_api(data, result_url):
12
 
13
- headers = {"Content-Type": "application/json"}
14
- response = requests.post(result_url, json=data, headers=headers)
15
- if response.status_code == 200:
16
- return response.json() # Return any response from the API if needed
17
- else:
18
- return {"error": f"Failed to send results to API: {response.status_code}"}
19
 
20
  def process_xlsx(params):
21
  # xlsx_file = 'https://fragilestatesindex.org/wp-content/uploads/2023/06/FSI-2023-DOWNLOAD.xlsx'
@@ -24,9 +24,9 @@ def process_xlsx(params):
24
  except json.JSONDecodeError as e:
25
  return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"}
26
 
27
- addresses = params.get("text_list", [])
28
- api = params.get("api", "")
29
- job_id = params.get("job_id", "")
30
 
31
  solutions=[]
32
  text_id = 0
@@ -43,23 +43,21 @@ def process_xlsx(params):
43
  entities_dict[ent.label_].append({'word': ent.text, 'index': idx})
44
 
45
  # Create the final output dictionary
46
- output = {
47
- 'text': adress,
48
- 'text_id': text_id,
49
- 'answer': entities_dict
50
- }
51
- solutions.append(output)
52
  text_id = text_id+1
53
 
54
- result_url = f"{api}/{job_id}"
55
- send_results_to_api(solutions, result_url)
56
 
57
- return json.dumps({"solutions": solutions}, indent=4)
58
 
59
 
60
  import gradio as gr
61
- inputt = gr.Textbox(label="Parameters (JSON format) Eg. {'audio_files':['file1.mp3','file2.wav'], 'api':'https://api.example.com', 'job_id':'1001'}")
62
  outputs = gr.JSON()
63
 
64
  application = gr.Interface(fn=process_xlsx, inputs=inputt, outputs=outputs, title="Named Entity Recognition with API Integration")
65
- application.launch(share=True)
 
8
  # Load your custom NER model
9
  nlp_ner = spacy.load("ner_model_v1")
10
 
11
+ # def send_results_to_api(data, result_url):
12
 
13
+ # headers = {"Content-Type": "application/json"}
14
+ # response = requests.post(result_url, json=data, headers=headers)
15
+ # if response.status_code == 200:
16
+ # return response.json() # Return any response from the API if needed
17
+ # else:
18
+ # return {"error": f"Failed to send results to API: {response.status_code}"}
19
 
20
  def process_xlsx(params):
21
  # xlsx_file = 'https://fragilestatesindex.org/wp-content/uploads/2023/06/FSI-2023-DOWNLOAD.xlsx'
 
24
  except json.JSONDecodeError as e:
25
  return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"}
26
 
27
+ addresses = params.get("texts", [])
28
+ # api = params.get("api", "")
29
+ # job_id = params.get("job_id", "")
30
 
31
  solutions=[]
32
  text_id = 0
 
43
  entities_dict[ent.label_].append({'word': ent.text, 'index': idx})
44
 
45
  # Create the final output dictionary
46
+ #
47
+ output = {'text_id': text_id, 'answer': entities_dict}
48
+ obj = {"text": adress, "answer":output}
49
+ solutions.append(obj)
 
 
50
  text_id = text_id+1
51
 
52
+ # result_url = f"{api}/{job_id}"
53
+ # send_results_to_api(solutions, result_url)
54
 
55
+ return json.dumps({"solutions": solutions})
56
 
57
 
58
  import gradio as gr
59
+ inputt = gr.Textbox(label="Parameters (JSON format) Eg. {'texts':['file1.mp3','file2.wav']}")
60
  outputs = gr.JSON()
61
 
62
  application = gr.Interface(fn=process_xlsx, inputs=inputt, outputs=outputs, title="Named Entity Recognition with API Integration")
63
+ application.launch()