Spaces:
Sleeping
Sleeping
File size: 683 Bytes
c1cfdc4 a2946a5 7866d1b c1cfdc4 7866d1b 4843ace a2946a5 c1cfdc4 2021aca c1cfdc4 4843ace 901a8b4 7866d1b 4843ace 7866d1b c1cfdc4 a2946a5 d20deed a2946a5 4843ace c1cfdc4 fa4bf75 c1cfdc4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
import keras_nlp
print("Modules loaded!")
print("Fetching model...")
model = keras_nlp.models.GemmaCausalLM.from_preset("hf://bhashwarsengupta/gemma2-instruct-2b-en-finance")
print("model successfully loaded!")
def respond(
message,
history: list[tuple[str, str]]
):
messages = f"Question:\n{message}\n\nAnswer:\n"
print("Generating response...")
output = model.generate(messages)
print("Response generated!")
# Split by "Answer:" from the right and get the last part
response = output.rsplit("Answer:\n", 1)[-1]
return response
demo = gr.ChatInterface(
respond
)
if __name__ == "__main__":
demo.launch()
|