Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,6 +34,24 @@ function refresh() {
|
|
34 |
|
35 |
previous_sessions = []
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# def add_session(prompt):
|
39 |
# global previous_sessions
|
@@ -46,27 +64,27 @@ previous_sessions = []
|
|
46 |
|
47 |
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
#
|
58 |
-
|
59 |
-
|
60 |
-
#
|
61 |
-
|
62 |
|
63 |
|
64 |
-
def inference(prompt):
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
|
72 |
# # def remember(prompt, result):
|
|
|
34 |
|
35 |
previous_sessions = []
|
36 |
|
37 |
+
def post_process_output(prompt, result):
|
38 |
+
# Remove the prompt if it's repeated at the beginning of the answer
|
39 |
+
answer = result.strip()
|
40 |
+
if answer.startswith(prompt):
|
41 |
+
answer = answer[len(prompt):].strip()
|
42 |
+
|
43 |
+
# Remove any leading colons or whitespace
|
44 |
+
answer = answer.lstrip(':')
|
45 |
+
|
46 |
+
# Ensure the answer starts with a capital letter
|
47 |
+
answer = answer.capitalize()
|
48 |
+
|
49 |
+
# Ensure the answer ends with a period if it doesn't already
|
50 |
+
if not answer.endswith('.'):
|
51 |
+
answer += '.'
|
52 |
+
|
53 |
+
return f"{answer}"
|
54 |
+
|
55 |
|
56 |
# def add_session(prompt):
|
57 |
# global previous_sessions
|
|
|
64 |
|
65 |
|
66 |
|
67 |
+
def inference(prompt):
|
68 |
+
prompt_text = prompt
|
69 |
+
generated_text = gemma_lm.generate(prompt_text)
|
70 |
|
71 |
+
#Apply post-processing
|
72 |
+
formatted_output = post_process_output(prompt_text, generated_text)
|
73 |
+
print(formatted_output)
|
74 |
|
75 |
+
#adding a bit of delay
|
76 |
+
time.sleep(1)
|
77 |
+
result = formatted_output
|
78 |
+
# sessions = add_session(prompt_text)
|
79 |
+
return result
|
80 |
|
81 |
|
82 |
+
# def inference(prompt):
|
83 |
|
84 |
+
# time.sleep(1)
|
85 |
+
# result = "Your Result"
|
86 |
+
# # sessions = add_session(prompt)
|
87 |
+
# return result
|
88 |
|
89 |
|
90 |
# # def remember(prompt, result):
|