File size: 755 Bytes
ab02957
71a012f
 
 
 
ab02957
 
 
71a012f
ab02957
71a012f
 
 
 
 
 
 
 
 
ab02957
71a012f
 
 
ab02957
71a012f
ab02957
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
import gradio as gr
import os
os.environ["KERAS_BACKEND"] = "tensorflow"                                                                           
import keras
import keras_nlp



gemma_lm = keras_nlp.models.CausalLM.from_preset("hf://sultan-hassan/CosmoGemma_2b_en")

def launch(input):
    template = "Instruction:\n{instruction}\n\nResponse:\n{response}"
    prompt = template.format(
        instruction=input,                                                                   
        response="",
    )
    out = gemma_lm.generate(prompt, max_length=256)
    ind = out.index('Response') + len('Response')+2
    return out[ind:]

iface = gr.Interface(launch,
                     inputs="text",
                     outputs="text")

iface.launch()