Spaces:
Build error
Build error
| 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() |