Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from transformers import GemmaTokenizer, AutoModelForCausalLM
|
4 |
+
|
5 |
+
# Set an environment variable
|
6 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
7 |
+
|
8 |
+
tokenizer = GemmaTokenizer.from_pretrained("google/codegemma-7b-it")
|
9 |
+
model = AutoModelForCausalLM.from_pretrained("google/codegemma-7b-it").to("cuda:0")
|
10 |
+
|
11 |
+
# sample input
|
12 |
+
input_text = "Write a Python function to calculate the nth fibonacci number.\n"
|
13 |
+
|
14 |
+
def codegemma(message, history, temperature, max_new_tokens,):
|
15 |
+
input_ids = tokenizer(message, return_tensors="pt").to("cuda:0")
|
16 |
+
outputs = model.generate(**input_ids,
|
17 |
+
temperature=temperature,
|
18 |
+
max_new_tokens=max_new_tokens,
|
19 |
+
)
|
20 |
+
response = tokenizer.decode(outputs[0])
|
21 |
+
return response
|
22 |
+
|
23 |
+
placeholder = """
|
24 |
+
<img src="https://huggingface.co/spaces/ysharma/CodeGemma/resolve/main/gemma_lockup_vertical_full-color_rgb.png" style="width:40%">
|
25 |
+
<b>CodeGemma-7B-IT</b>
|
26 |
+
"""
|
27 |
+
|
28 |
+
with gr.Blocks(fill_height=True) as demo:
|
29 |
+
gr.Markdown("# GEMMA-7b-IT")
|
30 |
+
#with gr.Tab('CodeGemma Chatbot'):
|
31 |
+
gr.ChatInterface(codegemma,
|
32 |
+
examples=[["Write a Python function to calculate the nth fibonacci number."]],
|
33 |
+
fill_height=True,
|
34 |
+
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
35 |
+
additional_inputs=[
|
36 |
+
gr.Slider(0, 1, 0.95, label="Temperature", render=False),
|
37 |
+
gr.Slider(128, 4096, 512, label="Max new tokens", render=False ),
|
38 |
+
],
|
39 |
+
)
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
demo.launch(debug=False)
|