YC-Chen commited on
Commit
645b098
1 Parent(s): 85d5ae5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -5,6 +5,7 @@ import time
5
 
6
  import gradio as gr
7
  from transformers import AutoTokenizer
 
8
 
9
 
10
  DESCRIPTION = """
@@ -47,6 +48,28 @@ MAX_SEC = 30
47
 
48
  tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breeze-7B-Instruct-v0_1")
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  def refusal_condition(query):
51
  # 不要再問這些問題啦!
52
 
@@ -187,8 +210,9 @@ with gr.Blocks() as demo:
187
  if refusal_condition(history[-1][1]):
188
  history[-1][1] = history[-1][1] + '\n\n**[免責聲明: Breeze-7B-Instruct 和 Breeze-7B-Instruct-64k 並未針對問答進行安全保護,因此語言模型的任何回應不代表 MediaTek Research 立場。]**'
189
  yield history
190
-
191
  print('== Record ==\nQuery: {query}\nResponse: {response}'.format(query=repr(message), response=repr(history[-1][1])))
 
192
 
193
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
194
  fn=bot,
 
5
 
6
  import gradio as gr
7
  from transformers import AutoTokenizer
8
+ import psycopg2
9
 
10
 
11
  DESCRIPTION = """
 
48
 
49
  tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breeze-7B-Instruct-v0_1")
50
 
51
+ def insert_to_db(prompt, response, temperature, top_p):
52
+ #Establishing the connection
53
+ conn = psycopg2.connect(
54
+ database=os.environ.get("DB"), user=os.environ.get("USER"), password=os.environ.get("DB_PASS"), host=os.environ.get("DB_HOST"), port= '5432'
55
+ )
56
+ #Setting auto commit false
57
+ conn.autocommit = True
58
+
59
+ #Creating a cursor object using the cursor() method
60
+ cursor = conn.cursor()
61
+
62
+ # Preparing SQL queries to INSERT a record into the database.
63
+ cursor.execute(f"INSERT INTO EMPLOYEE(prompt, response, temperature, top_p) VALUES ('{prompt}', '{response}', {temperature}, {top_p})")
64
+
65
+ # Commit your changes in the database
66
+ conn.commit()
67
+
68
+ # Closing the connection
69
+ conn.close()
70
+
71
+
72
+
73
  def refusal_condition(query):
74
  # 不要再問這些問題啦!
75
 
 
210
  if refusal_condition(history[-1][1]):
211
  history[-1][1] = history[-1][1] + '\n\n**[免責聲明: Breeze-7B-Instruct 和 Breeze-7B-Instruct-64k 並未針對問答進行安全保護,因此語言模型的任何回應不代表 MediaTek Research 立場。]**'
212
  yield history
213
+
214
  print('== Record ==\nQuery: {query}\nResponse: {response}'.format(query=repr(message), response=repr(history[-1][1])))
215
+ insert_to_db(message, history[-1][1], float(temperature), float(top_p))
216
 
217
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
218
  fn=bot,