Spaces:
Runtime error
Runtime error
jeevavijay10
commited on
Commit
•
0927bb7
0
Parent(s):
first commit
Browse files- .gitignore +1 -0
- app.py +21 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/models
|
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen25-7b-instruct", trust_remote_code=True)
|
5 |
+
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen25-7b-instruct", cache_dir="models/")
|
6 |
+
|
7 |
+
def code_gen(text):
|
8 |
+
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
9 |
+
generated_ids = model.generate(input_ids, max_length=128)
|
10 |
+
response = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
11 |
+
print(response)
|
12 |
+
return response
|
13 |
+
|
14 |
+
|
15 |
+
iface = gr.Interface(fn=code_gen,
|
16 |
+
inputs=gr.inputs.Textbox(
|
17 |
+
label="Input Source Code"),
|
18 |
+
outputs="text",
|
19 |
+
title="Code Generation")
|
20 |
+
|
21 |
+
iface.launch()
|