Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,23 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
3 |
import os
|
4 |
|
5 |
# Check if the token is being accessed
|
6 |
-
hf_token = os.
|
7 |
-
if hf_token:
|
8 |
-
print("Successfully retrieved Hugging Face token.")
|
9 |
-
else:
|
10 |
-
print("Failed to retrieve Hugging Face token.")
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
3 |
import os
|
4 |
|
5 |
# Check if the token is being accessed
|
6 |
+
hf_token = os.environ.get("HF_HOME", None)
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
# Load the model and tokenizer
|
9 |
+
model_name = "meta-llama/CodeLlama-7b-hf"
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, token=hf_token)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token)
|
12 |
|
13 |
|
14 |
+
def generate_code(prompt):
|
15 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
16 |
+
outputs = model.generate(inputs["input_ids"], max_length=200)
|
17 |
+
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return code
|
19 |
|
20 |
+
# Set up the Gradio interface
|
21 |
+
demo = gr.Interface(fn=generate_code,
|
22 |
+
inputs="text",
|
23 |
+
outputs="text",
|
24 |
+
title="CodeLlama 7B Model",
|
25 |
+
description="Generate code with CodeLlama-7b-hf.").launch()
|