File size: 752 Bytes
9225ce1
5b9f103
9225ce1
18390c0
5b9f103
 
9225ce1
 
5b9f103
 
9225ce1
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration

model_name = "t5-small"  # Correct model for T5
tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)

def generate_comments(code):
    inputs = tokenizer("Comment this code: " + code, return_tensors="pt")
    outputs = model.generate(inputs["input_ids"], max_length=200, num_return_sequences=1)
    commented_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return commented_code

iface = gr.Interface(
    fn=generate_comments,
    inputs="text",
    outputs="text",
    title="AI Code Commenter",
    description="Upload your code and let AI add meaningful comments."
)

iface.launch()