pragnakalp commited on
Commit
c6a2c72
1 Parent(s): 3b60e31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -7
app.py CHANGED
@@ -4,10 +4,19 @@ import gc
4
  import os
5
  import pandas as pd
6
 
7
- cwd = os.getcwd()
8
- model_path = os.path.join(cwd)
 
 
 
 
 
 
 
 
9
  tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion")
10
  model_base = AutoModelWithLMHead.from_pretrained(model_path)
 
11
  def get_emotion(text):
12
 
13
  # input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
@@ -45,13 +54,50 @@ def generate_emotion(article):
45
  # }
46
  result = {'Input':sen_list_temp, 'Detected Emotion':results}
47
  gc.collect()
48
- # print("LENGTH of results ====> ", results)
49
-
50
- return pd.DataFrame(result)
 
 
 
 
51
 
52
- inputs=gr.Textbox(lines=10, label="Sentences",elem_id="inp_div")
53
- outputs = [gr.Dataframe(row_count = (1, "dynamic"), col_count=(2, "fixed"), label="Here is the Result", headers=["Input","Detected Emotion"])]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
 
 
55
 
56
  demo = gr.Interface(
57
  generate_emotion,
 
4
  import os
5
  import pandas as pd
6
 
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+ DATASET_NAME = "emotion_detection"
9
+ DATASET_REPO_URL = f"https://huggingface.co/datasets/pragnakalp/{DATASET_NAME}"
10
+ DATA_FILENAME = "emotion_detection_logs.csv"
11
+ DATA_FILE = os.path.join("emotion_detection_logs", DATA_FILENAME)
12
+ DATASET_REPO_ID = "pragnakalp/emotion_detection"
13
+ print("is none?", HF_TOKEN is None)
14
+
15
+ sentences_value = """Raj loves Simran.\nLast year I lost my Dog.\nI bought a new phone!\nShe is scared of cockroaches.\nWow! I was not expecting that.\nShe got mad at him."""
16
+
17
  tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion")
18
  model_base = AutoModelWithLMHead.from_pretrained(model_path)
19
+
20
  def get_emotion(text):
21
 
22
  # input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
 
54
  # }
55
  result = {'Input':sen_list_temp, 'Detected Emotion':results}
56
  gc.collect()
57
+ add_csv = [results_dict]
58
+ with open(DATA_FILE, "a") as f:
59
+ writer = csv.writer(f)
60
+ # write the data
61
+ writer.writerow(add_csv)
62
+ commit_url = repo.push_to_hub()
63
+ print("commit data :",commit_url)
64
 
65
+ return pd.DataFrame(result)
66
+ """
67
+ Save generated details
68
+ """
69
+ # def save_data_and_sendmail(article,generated_questions,num_que,result):
70
+ # try:
71
+ # hostname = {}
72
+ # hostname = get_device_ip_address()
73
+ # url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
74
+ # # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
75
+ # myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
76
+ # x = requests.post(url, json = myobj)
77
+ # add_csv = [article, generated_questions, num_que]
78
+ # with open(DATA_FILE, "a") as f:
79
+ # writer = csv.writer(f)
80
+ # # write the data
81
+ # writer.writerow(add_csv)
82
+ # commit_url = repo.push_to_hub()
83
+ # print("commit data :",commit_url)
84
+ # # except Exception as e:
85
+ # # return "Error while storing data -->" + e
86
+
87
+ # # try:
88
+ # # with open(DATA_FILE, "r") as file:
89
+ # # data = json.load(file)
90
+ # # data.append(entry)
91
+ # # with open(DATA_FILE, "w") as file:
92
+ # # json.dump(data, file)
93
+ # # commit_url = repo.push_to_hub()
94
+ # except Exception as e:
95
+ # return "Error while sending mail" + e
96
+
97
+ # return "Successfully save data"
98
 
99
+ inputs = gr.Textbox(value=sentences_value,lines=10, label="Sentences",elem_id="inp_div")
100
+ outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), label="Here is the Result", headers=["Input","Detected Emotion"])]
101
 
102
  demo = gr.Interface(
103
  generate_emotion,