Neodranzer commited on
Commit
5620411
·
1 Parent(s): 6487c9c

add model long

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -13,31 +13,31 @@ with col1:
13
  with col2:
14
  st.markdown('''# Llama :blue[3.2] ''')
15
  st.markdown('''##### :gray[finetuned for SQL questions]''')
16
- llm = Llama.from_pretrained(repo_id="alessandroptsn/llama3_2sql_model",filename="*llama3_2sql_model.Q4_K_M.gguf",verbose=False)
17
 
18
  st.session_state.context_text ="""
19
  CREATE TABLE student (
20
  student_id INT PRIMARY KEY,
21
- name TEXT,
22
  age INT
23
  );
24
 
25
 
26
- INSERT INTO student (student_id, name, age)
27
  VALUES
28
  (1, 'Carlos Silva', 20),
29
  (2, 'Ana Oliveira', 22),
30
  (3, 'João Pereira', 19);
31
 
32
 
33
- CREATE TABLE subject (
34
- subject_id INT PRIMARY KEY,
35
- name TEXT,
36
  hours INT
37
  );
38
 
39
 
40
- INSERT INTO subject (subject_id, name, hours)
41
  VALUES
42
  (1, 'Mathematics', 60),
43
  (2, 'History', 40),
@@ -45,26 +45,31 @@ VALUES
45
 
46
 
47
  CREATE TABLE grades (
 
48
  student_id INT,
49
- subject_id INT,
50
  grade REAL,
51
- PRIMARY KEY (student_id, subject_id),
52
- FOREIGN KEY (student_id) REFERENCES student(student_id)
53
  );
54
 
55
 
56
- INSERT INTO grades (student_id, subject_id, grade)
57
  VALUES
58
- (1, 1, 8.5),
59
- (1, 2, 7.0),
60
- (2, 1, 9.0),
61
- (2, 3, 6.5),
62
- (3, 2, 7.5);
 
 
63
  """
64
 
65
- def on_upper_clicked():
66
  st.session_state.text = st.session_state.context_text
67
 
 
 
68
 
69
  query = st.text_input(label="Insert your question here")
70
 
@@ -72,19 +77,32 @@ col1, col2 = st.columns([1, 3])
72
 
73
  with col1:
74
  context_check = st.checkbox("Add context")
75
- if context_check:
76
- concatenated_context = st.session_state.context_text
77
- else:
78
- concatenated_context = ''
79
 
80
  if context_check:
81
- st.text_area("Press Ctrl+Enter to apply the context",st.session_state.context_text, key="text",height=700)
82
- st.button("Reset context", on_click=on_upper_clicked)
 
 
 
 
 
 
 
 
83
 
84
 
85
  with col2:
86
  if st.button("Answer"):
87
  start = time.time()
 
 
 
 
 
 
 
 
88
  st.session_state.resp = llm.create_chat_completion(
89
  messages=[
90
  {
@@ -95,7 +113,7 @@ with col2:
95
  "role" : "template",
96
  "content":"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
97
  ### Instruction:
98
- Company database: """+concatenated_context+"""
99
 
100
  ### Input:
101
  SQL Prompt: """+query+"""
@@ -106,7 +124,7 @@ with col2:
106
  Explanation: {}
107
  """
108
  }
109
- ]
110
  )
111
  end = time.time()
112
  st.session_state.total_time = end - start
 
13
  with col2:
14
  st.markdown('''# Llama :blue[3.2] ''')
15
  st.markdown('''##### :gray[finetuned for SQL questions]''')
16
+ llm = Llama.from_pretrained(repo_id="alessandroptsn/llama3_2sql_model_long",filename="*llama3_2sql_model_long.Q4_K_M.gguf",verbose=False,n_ctx=100000)
17
 
18
  st.session_state.context_text ="""
19
  CREATE TABLE student (
20
  student_id INT PRIMARY KEY,
21
+ student_name TEXT,
22
  age INT
23
  );
24
 
25
 
26
+ INSERT INTO student (student_id, student_name, age)
27
  VALUES
28
  (1, 'Carlos Silva', 20),
29
  (2, 'Ana Oliveira', 22),
30
  (3, 'João Pereira', 19);
31
 
32
 
33
+ CREATE TABLE topic (
34
+ topic_id INT PRIMARY KEY,
35
+ topic_name TEXT,
36
  hours INT
37
  );
38
 
39
 
40
+ INSERT INTO topic (topic_id, topic_name, hours)
41
  VALUES
42
  (1, 'Mathematics', 60),
43
  (2, 'History', 40),
 
45
 
46
 
47
  CREATE TABLE grades (
48
+ grades_id INT PRIMARY KEY,
49
  student_id INT,
50
+ topic_id INT,
51
  grade REAL,
52
+ FOREIGN KEY (student_id) REFERENCES student(student_id),
53
+ FOREIGN KEY (topic_id) REFERENCES topic(topic_id)
54
  );
55
 
56
 
57
+ INSERT INTO grades (grades_id,student_id, topic_id, grade)
58
  VALUES
59
+ (1,1, 1, 8.5),
60
+ (2,1, 2, 7.0),
61
+ (3,2, 1, 9.0),
62
+ (4,2, 3, 6.5),
63
+ (5,3, 2, 7.5),
64
+ (6,3, 3, 7.0);
65
+
66
  """
67
 
68
+ def context_text_clicked():
69
  st.session_state.text = st.session_state.context_text
70
 
71
+ def text_clicked2():
72
+ st.session_state.text = st.session_state.text
73
 
74
  query = st.text_input(label="Insert your question here")
75
 
 
77
 
78
  with col1:
79
  context_check = st.checkbox("Add context")
80
+
 
 
 
81
 
82
  if context_check:
83
+ test = st.session_state.context_text
84
+ st.session_state.test2 = test
85
+ st.text_area("For any change, click in 'Apply context'",test, key="text",height=700)
86
+ b1, b2 = st.columns(2)
87
+ with b1:
88
+ if st.button("Reset context", on_click=context_text_clicked):
89
+ st.session_state.concatenated_context = st.session_state.context_text
90
+ with b2:
91
+ if st.button("Apply context", on_click=text_clicked2):
92
+ st.session_state.concatenated_context = st.session_state.text
93
 
94
 
95
  with col2:
96
  if st.button("Answer"):
97
  start = time.time()
98
+ try:
99
+ final_context = st.session_state.concatenated_context
100
+ except:
101
+ try:
102
+ final_context = st.session_state.test2
103
+ except:
104
+ final_context = ''
105
+
106
  st.session_state.resp = llm.create_chat_completion(
107
  messages=[
108
  {
 
113
  "role" : "template",
114
  "content":"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
115
  ### Instruction:
116
+ Company database: """+final_context+"""
117
 
118
  ### Input:
119
  SQL Prompt: """+query+"""
 
124
  Explanation: {}
125
  """
126
  }
127
+ ]#,temperature=0.85
128
  )
129
  end = time.time()
130
  st.session_state.total_time = end - start