Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,8 @@ from googleapiclient.http import MediaFileUpload
|
|
10 |
from pathlib import Path
|
11 |
import argparse
|
12 |
from huggingface_hub import snapshot_download
|
13 |
-
|
|
|
14 |
|
15 |
#TODO : Cleanup and comment
|
16 |
|
@@ -56,26 +57,26 @@ Occupation = ""
|
|
56 |
Ethnicity = ""
|
57 |
Gender = ""
|
58 |
Age=""
|
|
|
59 |
|
60 |
chat_log_name =""
|
61 |
|
62 |
from llama_cpp import Llama
|
63 |
llm = Llama(model_path=model_file, model_type="mistral",n_gpu_layers=-1,n_ctx = 2048)
|
64 |
|
|
|
65 |
|
66 |
def load_model():
|
67 |
global llm
|
68 |
llm = Llama(model_path=model_file, model_type="mistral",n_gpu_layers=-1,n_ctx = 2048)
|
69 |
return "Model loaded"
|
70 |
|
71 |
-
def
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
chat_log_name = ""
|
78 |
-
return "Chat reset successfully. You can start a new chat now."
|
79 |
|
80 |
def get_drive_service():
|
81 |
credentials = service_account.Credentials.from_service_account_file(
|
@@ -116,6 +117,7 @@ def upload_to_google_drive():
|
|
116 |
data = {
|
117 |
"name": Name,
|
118 |
"occupation": Occupation,
|
|
|
119 |
"ethnicity": Ethnicity,
|
120 |
"gender": Gender,
|
121 |
"age": Age,
|
@@ -145,10 +147,9 @@ def upload_to_google_drive():
|
|
145 |
|
146 |
def generate(prompt, history):
|
147 |
|
148 |
-
global isFirstRun,initContext,Name,Occupation,Ethnicity,Gender,Age,context
|
149 |
|
150 |
-
if not len(Name) == 0 and not len(Occupation) == 0 and not len(Ethnicity) == 0 and not len(Gender) == 0 and not len(Age) == 0:
|
151 |
-
|
152 |
firstmsg =""
|
153 |
if isFirstRun:
|
154 |
context = initContext
|
@@ -197,16 +198,17 @@ def generate(prompt, history):
|
|
197 |
yield output
|
198 |
|
199 |
|
200 |
-
def name_interface(name,occupation,ethnicity,gender,age,reset_button):
|
201 |
-
global Name, Occupation,Ethnicity,Gender,Age,chat_log_name
|
202 |
print(reset_button)
|
203 |
Name = name
|
204 |
Occupation = occupation
|
205 |
Ethnicity=ethnicity
|
206 |
Gender=gender
|
207 |
Age=age
|
|
|
208 |
|
209 |
-
if name and occupation and ethnicity and gender and age:
|
210 |
chat_log_name = f'chat_log_for_{Name}_{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.json'
|
211 |
return f"You can start chatting now {Name}"
|
212 |
else:
|
@@ -220,9 +222,10 @@ def reset_chat_interface():
|
|
220 |
return "Chat has been reset."
|
221 |
|
222 |
def reset_name_interface():
|
223 |
-
global Name, Occupation, Ethnicity, Gender, Age, chat_log_name
|
224 |
Name = ""
|
225 |
Occupation = ""
|
|
|
226 |
Ethnicity = ""
|
227 |
Gender = ""
|
228 |
Age = ""
|
@@ -230,10 +233,12 @@ def reset_name_interface():
|
|
230 |
return "User info has been reset."
|
231 |
|
232 |
def reset_all():
|
|
|
233 |
message1 = reset_chat_interface()
|
234 |
message2 = reset_name_interface()
|
235 |
message3 = load_model()
|
236 |
-
|
|
|
237 |
|
238 |
chat_bot=gr.ChatInterface(
|
239 |
fn=generate,
|
@@ -244,10 +249,12 @@ chat_bot=gr.ChatInterface(
|
|
244 |
name_interface = gr.Interface(
|
245 |
fn=name_interface,
|
246 |
inputs=[
|
|
|
247 |
gr.Textbox(label="Name", placeholder="Enter your name here..."),
|
248 |
gr.Textbox(label="Occupation", placeholder="Enter your occupation here..."),
|
|
|
249 |
gr.Textbox(label="Ethnicity", placeholder="Enter your Ethnicity here..."),
|
250 |
-
gr.Dropdown(choices=["Male", "Female",
|
251 |
gr.Textbox(label="Age", placeholder="Enter your Age here..."),
|
252 |
],outputs="text",
|
253 |
title="ECU-IVADE : User Information",
|
|
|
10 |
from pathlib import Path
|
11 |
import argparse
|
12 |
from huggingface_hub import snapshot_download
|
13 |
+
import random
|
14 |
+
import string
|
15 |
|
16 |
#TODO : Cleanup and comment
|
17 |
|
|
|
57 |
Ethnicity = ""
|
58 |
Gender = ""
|
59 |
Age=""
|
60 |
+
YearsOfExp = ""
|
61 |
|
62 |
chat_log_name =""
|
63 |
|
64 |
from llama_cpp import Llama
|
65 |
llm = Llama(model_path=model_file, model_type="mistral",n_gpu_layers=-1,n_ctx = 2048)
|
66 |
|
67 |
+
unique_id = generate_unique_id()
|
68 |
|
69 |
def load_model():
|
70 |
global llm
|
71 |
llm = Llama(model_path=model_file, model_type="mistral",n_gpu_layers=-1,n_ctx = 2048)
|
72 |
return "Model loaded"
|
73 |
|
74 |
+
def generate_unique_id():
|
75 |
+
# Generate a random sequence of 3 letters and 3 digits
|
76 |
+
letters = ''.join(random.choices(string.ascii_letters, k=3))
|
77 |
+
digits = ''.join(random.choices(string.digits, k=3))
|
78 |
+
unique_id = letters + digits
|
79 |
+
return unique_id
|
|
|
|
|
80 |
|
81 |
def get_drive_service():
|
82 |
credentials = service_account.Credentials.from_service_account_file(
|
|
|
117 |
data = {
|
118 |
"name": Name,
|
119 |
"occupation": Occupation,
|
120 |
+
"years of experience": YearsOfExp,
|
121 |
"ethnicity": Ethnicity,
|
122 |
"gender": Gender,
|
123 |
"age": Age,
|
|
|
147 |
|
148 |
def generate(prompt, history):
|
149 |
|
150 |
+
global isFirstRun,initContext,Name,Occupation,Ethnicity,Gender,Age,context,YearsOfExp
|
151 |
|
152 |
+
if not len(Name) == 0 and not len(Occupation) == 0 and not len(Ethnicity) == 0 and not len(Gender) == 0 and not len(Age) == 0 and not len(YearsOfExp):
|
|
|
153 |
firstmsg =""
|
154 |
if isFirstRun:
|
155 |
context = initContext
|
|
|
198 |
yield output
|
199 |
|
200 |
|
201 |
+
def name_interface(name,occupation,yearsofexp,ethnicity,gender,age,reset_button):
|
202 |
+
global Name, Occupation,Ethnicity,Gender,Age,chat_log_name,YearsOfExp
|
203 |
print(reset_button)
|
204 |
Name = name
|
205 |
Occupation = occupation
|
206 |
Ethnicity=ethnicity
|
207 |
Gender=gender
|
208 |
Age=age
|
209 |
+
YearsOfExp = yearsofexp
|
210 |
|
211 |
+
if name and occupation and ethnicity and gender and age and yearsofexp:
|
212 |
chat_log_name = f'chat_log_for_{Name}_{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.json'
|
213 |
return f"You can start chatting now {Name}"
|
214 |
else:
|
|
|
222 |
return "Chat has been reset."
|
223 |
|
224 |
def reset_name_interface():
|
225 |
+
global Name, Occupation, Ethnicity, Gender, Age,YearsOfExp, chat_log_name
|
226 |
Name = ""
|
227 |
Occupation = ""
|
228 |
+
YearsOfExp = ""
|
229 |
Ethnicity = ""
|
230 |
Gender = ""
|
231 |
Age = ""
|
|
|
233 |
return "User info has been reset."
|
234 |
|
235 |
def reset_all():
|
236 |
+
global unique_id
|
237 |
message1 = reset_chat_interface()
|
238 |
message2 = reset_name_interface()
|
239 |
message3 = load_model()
|
240 |
+
unique_id = generate_unique_id()
|
241 |
+
return f"All Chat components have been rest. Uniqe ID for this session is, {unique_id}. Please note this down."
|
242 |
|
243 |
chat_bot=gr.ChatInterface(
|
244 |
fn=generate,
|
|
|
249 |
name_interface = gr.Interface(
|
250 |
fn=name_interface,
|
251 |
inputs=[
|
252 |
+
gr.Textbox(label="Unique ID", value = unique_id ,container = True, scale = 2 ,interactive = False, show_copy_button = True),
|
253 |
gr.Textbox(label="Name", placeholder="Enter your name here..."),
|
254 |
gr.Textbox(label="Occupation", placeholder="Enter your occupation here..."),
|
255 |
+
gr.Textbox(label="Years of Experience", placeholder="Enter the years of experience"),
|
256 |
gr.Textbox(label="Ethnicity", placeholder="Enter your Ethnicity here..."),
|
257 |
+
gr.Dropdown(choices=["Male", "Female","Other","Prefer Not To Say"], label="Gender"),
|
258 |
gr.Textbox(label="Age", placeholder="Enter your Age here..."),
|
259 |
],outputs="text",
|
260 |
title="ECU-IVADE : User Information",
|