Spaces:
Sleeping
Sleeping
freshbash
commited on
Commit
·
a2946a5
1
Parent(s):
695ae2d
using keras model
Browse files
app.py
CHANGED
@@ -1,11 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
-
client = InferenceClient("bhashwarsengupta/gemma-finance")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -15,29 +24,27 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
messages =
|
19 |
|
20 |
for val in history:
|
21 |
if val[0]:
|
22 |
-
messages
|
23 |
if val[1]:
|
24 |
-
messages
|
25 |
-
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
temperature=temperature,
|
35 |
-
top_p=
|
36 |
-
)
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
|
43 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
+
import keras_nlp
|
3 |
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
|
|
7 |
|
8 |
+
model = keras_nlp.models.GemmaCausalLM.from_preset("kaggle://bhashwar22/gemma-for-finance/keras/gemma-for-finance")
|
9 |
+
print("model successfully loaded!")
|
10 |
+
|
11 |
+
context = """You are an intelligent personal finance assistant
|
12 |
+
designed to help users understand various financial concepts.
|
13 |
+
You are supposed to provide concise and easy-to-understand explanations for the requested questions,
|
14 |
+
ensuring the users feel informed and confident about managing their money.
|
15 |
+
Keep your answers limited to 50-100 words.
|
16 |
+
If you receive any non-finance related query, please return the following response:
|
17 |
+
\"Unrelated Topic\""""
|
18 |
|
19 |
def respond(
|
20 |
message,
|
|
|
24 |
temperature,
|
25 |
top_p,
|
26 |
):
|
27 |
+
messages = f"Context: {context}\n"
|
28 |
|
29 |
for val in history:
|
30 |
if val[0]:
|
31 |
+
messages += f"Question: {val[0]}\n"
|
32 |
if val[1]:
|
33 |
+
messages += f"Answer: {val[1]}\n"
|
|
|
|
|
34 |
|
35 |
+
messages += f"Question: {message}\nAnswer: "
|
36 |
|
37 |
+
output = model.generate(
|
38 |
messages,
|
39 |
max_tokens=max_tokens,
|
|
|
40 |
temperature=temperature,
|
41 |
+
top_p=top_o
|
42 |
+
)
|
|
|
43 |
|
44 |
+
# Split by "Answer:" from the right and get the last part
|
45 |
+
response = output.rsplit("Answer: ", 1)[-1]
|
46 |
+
|
47 |
+
return response
|
48 |
|
49 |
|
50 |
"""
|