pragnakalp commited on
Commit
84c894b
1 Parent(s): 7374dd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -45,26 +45,20 @@ model_base = AutoModelWithLMHead.from_pretrained(model_path)
45
  get ip address
46
  """
47
  def get_device_ip_address():
48
- result = {}
49
  if os.name == "nt":
50
  result = "Running on Windows"
51
  hostname = socket.gethostname()
52
  ip_address = socket.gethostbyname(hostname)
53
- result['ip_addr'] = ip_address
54
- result['host'] = hostname
55
  print(ip_address)
56
- return result
57
  elif os.name == "posix":
58
  gw = os.popen("ip -4 route show default").read().split()
59
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
60
  s.connect((gw[2], 0))
61
- ipaddr = s.getsockname()[0]
62
  gateway = gw[2]
63
  host = socket.gethostname()
64
- result['ip_addr'] = ipaddr
65
- result['host'] = host
66
- print(result)
67
- return result
68
  else:
69
  result['id'] = os.name + " not supported yet."
70
  print(result)
@@ -121,10 +115,10 @@ def save_data_and_sendmail(article,results_dict,sen_list,results):
121
  try:
122
  print("sen_list^^^^^ ",sen_list)
123
  print("results^^^^^^ ",results)
124
- hostname = {}
125
- hostname = get_device_ip_address()
126
 
127
- add_csv = [article,results_dict,hostname.get("ip_addr","")]
128
  with open(DATA_FILE, "a") as f:
129
  writer = csv.writer(f)
130
  # write the data
@@ -136,7 +130,7 @@ def save_data_and_sendmail(article,results_dict,sen_list,results):
136
  # url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_emotion_detection'
137
  # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
138
 
139
- myobj = {"sentences":sen_list,"gen_results":results,"ip_addr":hostname.get("ip_addr",""),"host":hostname.get("host","")}
140
  print("myobj###### ",myobj)
141
  response = requests.post(url, json = myobj)
142
  print("response=-----=",response.status_code)
 
45
  get ip address
46
  """
47
  def get_device_ip_address():
 
48
  if os.name == "nt":
49
  result = "Running on Windows"
50
  hostname = socket.gethostname()
51
  ip_address = socket.gethostbyname(hostname)
 
 
52
  print(ip_address)
53
+ return ip_address
54
  elif os.name == "posix":
55
  gw = os.popen("ip -4 route show default").read().split()
56
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
57
  s.connect((gw[2], 0))
58
+ ip_address = s.getsockname()[0]
59
  gateway = gw[2]
60
  host = socket.gethostname()
61
+ return ip_address
 
 
 
62
  else:
63
  result['id'] = os.name + " not supported yet."
64
  print(result)
 
115
  try:
116
  print("sen_list^^^^^ ",sen_list)
117
  print("results^^^^^^ ",results)
118
+ ip_address = ''
119
+ ip_address = get_device_ip_address()
120
 
121
+ add_csv = [article,results_dict,ip_address]
122
  with open(DATA_FILE, "a") as f:
123
  writer = csv.writer(f)
124
  # write the data
 
130
  # url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_emotion_detection'
131
  # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
132
 
133
+ myobj = {"sentences":sen_list,"gen_results":results,"ip_addr":ip_address}
134
  print("myobj###### ",myobj)
135
  response = requests.post(url, json = myobj)
136
  print("response=-----=",response.status_code)