Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the DeepSeek-Coder model
|
5 |
+
model_name = "deepseek-ai/deepseek-coder-6.7b-instruct" # You can use any LLaMA-based model
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Function to generate comments
|
10 |
+
def generate_code_comments(code_snippet):
|
11 |
+
prompt = f"### Code:\n{code_snippet}\n### Add meaningful comments to this code:\n"
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
13 |
+
outputs = model.generate(**inputs, max_length=512)
|
14 |
+
commented_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
+
return commented_code
|
16 |
+
|
17 |
+
# Create Gradio interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=generate_code_comments,
|
20 |
+
inputs="text",
|
21 |
+
outputs="text",
|
22 |
+
title="AI Code Comment Generator",
|
23 |
+
description="Enter a code snippet, and the AI will add meaningful comments.",
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch()
|