Spaces:
Running
Running
pragnakalp
commited on
Commit
·
0683b76
1
Parent(s):
59efec1
Update app.py
Browse files
app.py
CHANGED
@@ -42,27 +42,61 @@ tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion")
|
|
42 |
model_base = AutoModelWithLMHead.from_pretrained(model_path)
|
43 |
|
44 |
"""
|
45 |
-
get ip address
|
46 |
"""
|
47 |
-
def get_device_ip_address():
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
return ip_address
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
"""
|
68 |
generate emotions of the sentences
|
@@ -103,8 +137,6 @@ def generate_emotion(article):
|
|
103 |
|
104 |
result = {'Input':sen_list_temp, 'Detected Emotion':results}
|
105 |
gc.collect()
|
106 |
-
print("sen_list@@@@@@@@@ ",sen_list)
|
107 |
-
print("results_dict@@@@@@@@ ",results_dict)
|
108 |
save_data_and_sendmail(article,results_dict,sen_list, results)
|
109 |
return pd.DataFrame(result)
|
110 |
|
@@ -113,13 +145,13 @@ Save generated details
|
|
113 |
"""
|
114 |
def save_data_and_sendmail(article,results_dict,sen_list,results):
|
115 |
try:
|
116 |
-
|
117 |
-
|
118 |
-
print(
|
119 |
-
|
120 |
-
|
121 |
|
122 |
-
add_csv = [article,results_dict,ip_address]
|
123 |
with open(DATA_FILE, "a") as f:
|
124 |
writer = csv.writer(f)
|
125 |
# write the data
|
@@ -129,9 +161,8 @@ def save_data_and_sendmail(article,results_dict,sen_list,results):
|
|
129 |
|
130 |
url = 'https://pragnakalpdev33.pythonanywhere.com/emotion_detection_demo'
|
131 |
# url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_emotion_detection'
|
132 |
-
# url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
133 |
|
134 |
-
myobj = {"sentences":sen_list,"gen_results":results,"ip_addr":ip_address}
|
135 |
print("myobj###### ",myobj)
|
136 |
response = requests.post(url, json = myobj)
|
137 |
print("response=-----=",response.status_code)
|
@@ -146,7 +177,7 @@ def save_data_and_sendmail(article,results_dict,sen_list,results):
|
|
146 |
UI design for demo using gradio app
|
147 |
"""
|
148 |
inputs = gr.Textbox(value=SENTENCES_VALUE,lines=3, label="Sentences",elem_id="inp_div")
|
149 |
-
outputs = [gr.Dataframe(row_count = (
|
150 |
|
151 |
demo = gr.Interface(
|
152 |
generate_emotion,
|
|
|
42 |
model_base = AutoModelWithLMHead.from_pretrained(model_path)
|
43 |
|
44 |
"""
|
45 |
+
get ip address and location
|
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)
|
65 |
+
# return result
|
66 |
+
|
67 |
+
def getIP():
|
68 |
+
ip_address = ''
|
69 |
+
try:
|
70 |
+
d = str(urlopen('http://checkip.dyndns.com/')
|
71 |
+
.read())
|
72 |
+
|
73 |
+
return r.compile(r'Address: (\d+\.\d+\.\d+\.\d+)').search(d).group(1)
|
74 |
+
except Exception as e:
|
75 |
+
print("Error while getting IP address -->",e)
|
76 |
return ip_address
|
77 |
+
|
78 |
+
def get_location(ip_addr):
|
79 |
+
location = {}
|
80 |
+
try:
|
81 |
+
ip=ip_addr
|
82 |
+
|
83 |
+
req_data={
|
84 |
+
"ip":ip,
|
85 |
+
"token":"pkml123"
|
86 |
+
}
|
87 |
+
url = "https://demos.pragnakalp.com/get-ip-location"
|
88 |
+
|
89 |
+
# req_data=json.dumps(req_data)
|
90 |
+
# print("req_data",req_data)
|
91 |
+
headers = {'Content-Type': 'application/json'}
|
92 |
+
|
93 |
+
response = requests.request("POST", url, headers=headers, data=json.dumps(req_data))
|
94 |
+
response = response.json()
|
95 |
+
print("response======>>",response)
|
96 |
+
return response
|
97 |
+
except Exception as e:
|
98 |
+
print("Error while getting location -->",e)
|
99 |
+
return location
|
100 |
|
101 |
"""
|
102 |
generate emotions of the sentences
|
|
|
137 |
|
138 |
result = {'Input':sen_list_temp, 'Detected Emotion':results}
|
139 |
gc.collect()
|
|
|
|
|
140 |
save_data_and_sendmail(article,results_dict,sen_list, results)
|
141 |
return pd.DataFrame(result)
|
142 |
|
|
|
145 |
"""
|
146 |
def save_data_and_sendmail(article,results_dict,sen_list,results):
|
147 |
try:
|
148 |
+
|
149 |
+
ip_address= getIP()
|
150 |
+
print(ip_address)
|
151 |
+
location = get_location(ip_address)
|
152 |
+
print(location)
|
153 |
|
154 |
+
add_csv = [article,results_dict,ip_address,location]
|
155 |
with open(DATA_FILE, "a") as f:
|
156 |
writer = csv.writer(f)
|
157 |
# write the data
|
|
|
161 |
|
162 |
url = 'https://pragnakalpdev33.pythonanywhere.com/emotion_detection_demo'
|
163 |
# url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_emotion_detection'
|
|
|
164 |
|
165 |
+
myobj = {"sentences":sen_list,"gen_results":results,"ip_addr":ip_address,'loc':location}
|
166 |
print("myobj###### ",myobj)
|
167 |
response = requests.post(url, json = myobj)
|
168 |
print("response=-----=",response.status_code)
|
|
|
177 |
UI design for demo using gradio app
|
178 |
"""
|
179 |
inputs = gr.Textbox(value=SENTENCES_VALUE,lines=3, label="Sentences",elem_id="inp_div")
|
180 |
+
outputs = [gr.Dataframe(row_count = (3, "dynamic"), col_count=(2, "fixed"), label="Here is the Result", headers=["Input","Detected Emotion"])]
|
181 |
|
182 |
demo = gr.Interface(
|
183 |
generate_emotion,
|