Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
os.environ["KERAS_BACKEND"] = "tensorflow"
|
| 4 |
import keras
|
| 5 |
import keras_nlp
|
| 6 |
-
|
| 7 |
|
| 8 |
css = """
|
| 9 |
html, body {
|
|
@@ -35,18 +35,24 @@ body::before {
|
|
| 35 |
}
|
| 36 |
"""
|
| 37 |
|
| 38 |
-
keras.config.set_floatx("bfloat16")
|
| 39 |
gemma_lm = keras_nlp.models.CausalLM.from_preset("hf://sultan-hassan/CosmoGemma_2b_en")
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
|
| 43 |
-
prompt = template.format(
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
)
|
| 47 |
-
out = gemma_lm.generate(prompt, max_length=1024)
|
| 48 |
-
ind = out.index('
|
| 49 |
-
return out[ind:]
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
iface = gr.Interface(launch,
|
| 52 |
inputs="text",
|
|
|
|
| 3 |
os.environ["KERAS_BACKEND"] = "tensorflow"
|
| 4 |
import keras
|
| 5 |
import keras_nlp
|
| 6 |
+
import utils
|
| 7 |
|
| 8 |
css = """
|
| 9 |
html, body {
|
|
|
|
| 35 |
}
|
| 36 |
"""
|
| 37 |
|
| 38 |
+
#keras.config.set_floatx("bfloat16") uncomment to run at half precision.
|
| 39 |
gemma_lm = keras_nlp.models.CausalLM.from_preset("hf://sultan-hassan/CosmoGemma_2b_en")
|
| 40 |
+
chat = utils.ChatState(gemma_lm) # adding a chat helper to manage the conversation state (modified version from https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Keras_Gemma_2_Quickstart_Chat.ipynb)
|
| 41 |
+
|
| 42 |
+
def launch(message):
|
| 43 |
|
| 44 |
+
# Uncomment for QA system without chat history/memory
|
| 45 |
+
#template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
|
| 46 |
+
#prompt = template.format(
|
| 47 |
+
# instruction=message,
|
| 48 |
+
# response="",
|
| 49 |
+
#)
|
| 50 |
+
#out = gemma_lm.generate(prompt, max_length=1024)
|
| 51 |
+
#ind = out.index('\n\nResponse:\n') + len('\n\nResponse:\n')
|
| 52 |
+
#return out[ind:]
|
| 53 |
+
|
| 54 |
+
# This is to convert QA system to a chatbot
|
| 55 |
+
return chat.send_message(message)
|
| 56 |
|
| 57 |
iface = gr.Interface(launch,
|
| 58 |
inputs="text",
|