File size: 1,696 Bytes
5138ffd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
import gradio as gr
import os
from transformers import GemmaTokenizer, AutoModelForCausalLM

# Set an environment variable
HF_TOKEN = os.environ.get("HF_TOKEN", None)

tokenizer = GemmaTokenizer.from_pretrained("google/codegemma-7b-it")
model = AutoModelForCausalLM.from_pretrained("google/codegemma-7b-it").to("cuda:0")

# sample input
input_text = "Write a Python function to calculate the nth fibonacci number.\n"

def codegemma(message, history, temperature, max_new_tokens,):
  input_ids = tokenizer(message, return_tensors="pt").to("cuda:0")
  outputs = model.generate(**input_ids,
                           temperature=temperature,
                           max_new_tokens=max_new_tokens,
  )
  response = tokenizer.decode(outputs[0])
  return response
    
placeholder = """
<img src="https://huggingface.co./spaces/ysharma/CodeGemma/resolve/main/gemma_lockup_vertical_full-color_rgb.png" style="width:40%">
<b>CodeGemma-7B-IT</b>
"""

with gr.Blocks(fill_height=True) as demo:
      gr.Markdown("# GEMMA-7b-IT")
      #with gr.Tab('CodeGemma Chatbot'):
      gr.ChatInterface(codegemma, 
                       examples=[["Write a Python function to calculate the nth fibonacci number."]], 
                       fill_height=True,
                       additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
                       additional_inputs=[
                           gr.Slider(0, 1, 0.95, label="Temperature", render=False),
                           gr.Slider(128, 4096, 512, label="Max new tokens", render=False ),
                           ],
                       )
    
if __name__ == "__main__":
    demo.launch(debug=False)