pragnakalp commited on
Commit
662387f
1 Parent(s): 1f43064

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -24
app.py CHANGED
@@ -14,7 +14,7 @@ import csv
14
  qg = QuestionGenerator()
15
 
16
  HF_TOKEN = os.environ.get("HF_TOKEN")
17
- DATASET_NAME = "Question_Generation_T5"
18
  DATASET_REPO_URL = f"https://huggingface.co/datasets/pragnakalp/{DATASET_NAME}"
19
  DATA_FILENAME = "que_gen_logs.csv"
20
  DATA_FILE = os.path.join("que_gen_logs", DATA_FILENAME)
@@ -41,15 +41,11 @@ repo = Repository(
41
  )
42
 
43
  def get_device_ip_address():
44
- result = {}
45
  if os.name == "nt":
46
  result = "Running on Windows"
47
  hostname = socket.gethostname()
48
  ip_address = socket.gethostbyname(hostname)
49
- result['ip_addr'] = ip_address
50
- result['host'] = hostname
51
- print(result)
52
- return result
53
  elif os.name == "posix":
54
  gw = os.popen("ip -4 route show default").read().split()
55
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -57,15 +53,30 @@ def get_device_ip_address():
57
  ipaddr = s.getsockname()[0]
58
  gateway = gw[2]
59
  host = socket.gethostname()
60
- result['ip_addr'] = ipaddr
61
- result['host'] = host
62
- print(result)
63
- return result
64
  else:
65
  result['id'] = os.name + " not supported yet."
66
  print(result)
67
  return result
68
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  def generate_questions(article,num_que):
70
  result = ''
71
  try:
@@ -91,23 +102,24 @@ Save generated details
91
  """
92
  def save_data_and_sendmail(article,generated_questions,num_que,result):
93
  try:
94
- hostname = {}
95
- hostname = get_device_ip_address()
96
- url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
97
- # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
98
- myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
99
- x = requests.post(url, json = myobj)
100
- add_csv = [article, generated_questions, num_que]
101
  with open(DATA_FILE, "a") as f:
102
  writer = csv.writer(f)
103
  # write the data
104
  writer.writerow(add_csv)
105
  commit_url = repo.push_to_hub()
106
  print("commit data :",commit_url)
107
- # except Exception as e:
108
- # return "Error while storing data -->" + e
109
-
110
- # try:
 
 
111
  # with open(DATA_FILE, "r") as file:
112
  # data = json.load(file)
113
  # data.append(entry)
@@ -129,7 +141,10 @@ demo = gr.Interface(
129
  [inputs,total_que],
130
  outputs,
131
  title="Question Generation using T5",
132
- description="Feel free to give your feedback",
133
- css=".gradio-container {background-color: lightgray} #inp_div {background-color: #7FB3D5;}"
 
 
 
134
  )
135
  demo.launch(enable_queue = False)
 
14
  qg = QuestionGenerator()
15
 
16
  HF_TOKEN = os.environ.get("HF_TOKEN")
17
+ DATASET_NAME = "question_generation_T5_dataset"
18
  DATASET_REPO_URL = f"https://huggingface.co/datasets/pragnakalp/{DATASET_NAME}"
19
  DATA_FILENAME = "que_gen_logs.csv"
20
  DATA_FILE = os.path.join("que_gen_logs", DATA_FILENAME)
 
41
  )
42
 
43
  def get_device_ip_address():
 
44
  if os.name == "nt":
45
  result = "Running on Windows"
46
  hostname = socket.gethostname()
47
  ip_address = socket.gethostbyname(hostname)
48
+ return ip_address
 
 
 
49
  elif os.name == "posix":
50
  gw = os.popen("ip -4 route show default").read().split()
51
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
53
  ipaddr = s.getsockname()[0]
54
  gateway = gw[2]
55
  host = socket.gethostname()
56
+ return ip_address
 
 
 
57
  else:
58
  result['id'] = os.name + " not supported yet."
59
  print(result)
60
  return result
61
+
62
+ def get_location(ip_addr):
63
+ ip=ip_addr
64
+ # ip=str(request.remote_addr)
65
+ req_data={
66
+ "ip":ip,
67
+ "token":"pkml123"
68
+ }
69
+ url = "https://demos.pragnakalp.com/get-ip-location"
70
+
71
+ # req_data=json.dumps(req_data)
72
+ # print("req_data",req_data)
73
+ headers = {'Content-Type': 'application/json'}
74
+
75
+ response = requests.request("POST", url, headers=headers, data=json.dumps(req_data))
76
+ response = response.json()
77
+ print("response======>>",response)
78
+ return response
79
+
80
  def generate_questions(article,num_que):
81
  result = ''
82
  try:
 
102
  """
103
  def save_data_and_sendmail(article,generated_questions,num_que,result):
104
  try:
105
+ ip_address = ''
106
+ ip_address = get_device_ip_address()
107
+ location = get_location(ip_address)
108
+
109
+ add_csv = [article, generated_questions, num_que, ip_address, location]
110
+ print("data^^^^^",add_csv)
 
111
  with open(DATA_FILE, "a") as f:
112
  writer = csv.writer(f)
113
  # write the data
114
  writer.writerow(add_csv)
115
  commit_url = repo.push_to_hub()
116
  print("commit data :",commit_url)
117
+
118
+ url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
119
+ # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
120
+ myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
121
+ x = requests.post(url, json = myobj)
122
+ print("myobj^^^^^",myobj)
123
  # with open(DATA_FILE, "r") as file:
124
  # data = json.load(file)
125
  # data.append(entry)
 
141
  [inputs,total_que],
142
  outputs,
143
  title="Question Generation using T5",
144
+ css=".gradio-container {background-color: lightgray} #inp_div {background-color: #7FB3D5;}",
145
+ article="""Feel free to give us your [feedback](https://www.pragnakalp.com/contact/) on this NER demo. For all your Named Entity Recognition related
146
+ requirements, we are here to help you. Email us your requirement at [[email protected]]("mailto:[email protected]").
147
+ And don't forget to check out more interesting [NLP services](https://www.pragnakalp.com/services/natural-language-processing-services/) we are offering.
148
+ <p style='text-align: center;'>Developed by :[ Pragnakalp Techlabs](https://www.pragnakalp.com)</p>"""
149
  )
150
  demo.launch(enable_queue = False)