Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,6 @@ import time
|
|
6 |
# Initialize the pipeline with the new model
|
7 |
pipe = pipeline("text-generation", model="Blexus/Quble_test_model_v1_INSTRUCT_v1")
|
8 |
|
9 |
-
DATABASE_PATH = "database.json"
|
10 |
-
|
11 |
-
def load_database():
|
12 |
-
try:
|
13 |
-
with open(DATABASE_PATH, "r") as file:
|
14 |
-
return json.load(file)
|
15 |
-
except FileNotFoundError:
|
16 |
-
return {}
|
17 |
-
|
18 |
-
def save_database(database):
|
19 |
-
with open(DATABASE_PATH, "w") as file:
|
20 |
-
json.dump(database, file)
|
21 |
-
|
22 |
def format_prompt(message, system, history):
|
23 |
prompt = f"SYSTEM: {system}\n<|endofsystem|>\n"
|
24 |
|
@@ -31,7 +18,6 @@ def format_prompt(message, system, history):
|
|
31 |
return prompt
|
32 |
|
33 |
def generate(prompt, system, history, temperature=0.9, max_new_tokens=4096, top_p=0.9, repetition_penalty=1.2):
|
34 |
-
database = load_database()
|
35 |
temperature = float(temperature)
|
36 |
if temperature < 1e-2:
|
37 |
temperature = 1e-2
|
@@ -39,12 +25,8 @@ def generate(prompt, system, history, temperature=0.9, max_new_tokens=4096, top_
|
|
39 |
|
40 |
formatted_prompt = format_prompt(prompt, system, history)
|
41 |
response_text = "We are sorry but Quble doesn't know how to answer."
|
42 |
-
|
43 |
-
|
44 |
-
response_text = database[formatted_prompt]
|
45 |
-
else:
|
46 |
-
# Generate the response without streaming
|
47 |
-
try:
|
48 |
response = pipe(formatted_prompt, max_new_tokens=max_new_tokens, temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty)[0]["generated_text"]
|
49 |
response_text = response.split("ASSISTANT:")[-1].strip()
|
50 |
|
@@ -53,12 +35,9 @@ def generate(prompt, system, history, temperature=0.9, max_new_tokens=4096, top_
|
|
53 |
for char in response_text:
|
54 |
accumulated_response += char # Append the new character
|
55 |
yield accumulated_response # Yield the accumulated response
|
56 |
-
time.sleep(0.
|
57 |
|
58 |
-
|
59 |
-
database[formatted_prompt] = response_text
|
60 |
-
save_database(database)
|
61 |
-
except Exception as e:
|
62 |
print(f"Error generating response: {e}")
|
63 |
|
64 |
customCSS = """
|
|
|
6 |
# Initialize the pipeline with the new model
|
7 |
pipe = pipeline("text-generation", model="Blexus/Quble_test_model_v1_INSTRUCT_v1")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def format_prompt(message, system, history):
|
10 |
prompt = f"SYSTEM: {system}\n<|endofsystem|>\n"
|
11 |
|
|
|
18 |
return prompt
|
19 |
|
20 |
def generate(prompt, system, history, temperature=0.9, max_new_tokens=4096, top_p=0.9, repetition_penalty=1.2):
|
|
|
21 |
temperature = float(temperature)
|
22 |
if temperature < 1e-2:
|
23 |
temperature = 1e-2
|
|
|
25 |
|
26 |
formatted_prompt = format_prompt(prompt, system, history)
|
27 |
response_text = "We are sorry but Quble doesn't know how to answer."
|
28 |
+
# Generate the response without streaming
|
29 |
+
try:
|
|
|
|
|
|
|
|
|
30 |
response = pipe(formatted_prompt, max_new_tokens=max_new_tokens, temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty)[0]["generated_text"]
|
31 |
response_text = response.split("ASSISTANT:")[-1].strip()
|
32 |
|
|
|
35 |
for char in response_text:
|
36 |
accumulated_response += char # Append the new character
|
37 |
yield accumulated_response # Yield the accumulated response
|
38 |
+
time.sleep(0.02) # Add a slight delay to simulate typing
|
39 |
|
40 |
+
except Exception as e:
|
|
|
|
|
|
|
41 |
print(f"Error generating response: {e}")
|
42 |
|
43 |
customCSS = """
|