Upload folder using huggingface_hub
Browse files- README.md +12 -12
- app.py +28 -28
- requirements.txt +4 -4
README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Python Docstring Generator
|
| 3 |
-
emoji: 📝
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: blue
|
| 6 |
-
sdk: docker
|
| 7 |
-
app_port: 7860
|
| 8 |
-
---
|
| 9 |
-
|
| 10 |
-
# Python Docstring Generator
|
| 11 |
-
|
| 12 |
-
Paste a Python code snippet to get a short docstring summary (T5-based). By [syeedalireza](https://huggingface.co/syeedalireza).
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Python Docstring Generator
|
| 3 |
+
emoji: 📝
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Python Docstring Generator
|
| 11 |
+
|
| 12 |
+
Paste a Python code snippet to get a short docstring summary (T5-based). By [syeedalireza](https://huggingface.co/syeedalireza).
|
app.py
CHANGED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Gradio Space: Python docstring generation.
|
| 3 |
-
HF runs the app; do not call demo.launch() here.
|
| 4 |
-
"""
|
| 5 |
-
import gradio as gr
|
| 6 |
-
|
| 7 |
-
def summarize_code(code: str) -> str:
|
| 8 |
-
if not code or not code.strip():
|
| 9 |
-
return "Paste a Python code snippet above."
|
| 10 |
-
try:
|
| 11 |
-
from inference import generate_docstring
|
| 12 |
-
return generate_docstring(code, model_name="t5-small", max_length=128, num_beams=4)
|
| 13 |
-
except Exception as e:
|
| 14 |
-
return f"Error: {str(e)}. (Model may be loading; try again.)"
|
| 15 |
-
|
| 16 |
-
demo = gr.Interface(
|
| 17 |
-
fn=summarize_code,
|
| 18 |
-
inputs=gr.Textbox(
|
| 19 |
-
label="Python code",
|
| 20 |
-
placeholder="def add(a, b):\n return a + b",
|
| 21 |
-
lines=8,
|
| 22 |
-
),
|
| 23 |
-
outputs=gr.Textbox(label="Generated docstring"),
|
| 24 |
-
title="Python Docstring Generator",
|
| 25 |
-
description="Paste a Python function or snippet to get a short docstring summary.",
|
| 26 |
-
)
|
| 27 |
-
if __name__ == "__main__":
|
| 28 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Gradio Space: Python docstring generation.
|
| 3 |
+
HF runs the app; do not call demo.launch() here.
|
| 4 |
+
"""
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
def summarize_code(code: str) -> str:
|
| 8 |
+
if not code or not code.strip():
|
| 9 |
+
return "Paste a Python code snippet above."
|
| 10 |
+
try:
|
| 11 |
+
from inference import generate_docstring
|
| 12 |
+
return generate_docstring(code, model_name="t5-small", max_length=128, num_beams=4)
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return f"Error: {str(e)}. (Model may be loading; try again.)"
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(
|
| 17 |
+
fn=summarize_code,
|
| 18 |
+
inputs=gr.Textbox(
|
| 19 |
+
label="Python code",
|
| 20 |
+
placeholder="def add(a, b):\n return a + b",
|
| 21 |
+
lines=8,
|
| 22 |
+
),
|
| 23 |
+
outputs=gr.Textbox(label="Generated docstring"),
|
| 24 |
+
title="Python Docstring Generator",
|
| 25 |
+
description="Paste a Python function or snippet to get a short docstring summary.",
|
| 26 |
+
)
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
gradio==4.44.0
|
| 2 |
-
huggingface_hub>=0.20.0,<1.0
|
| 3 |
-
torch>=2.0.0
|
| 4 |
-
transformers>=4.30.0
|
|
|
|
| 1 |
+
gradio==4.44.0
|
| 2 |
+
huggingface_hub>=0.20.0,<1.0
|
| 3 |
+
torch>=2.0.0
|
| 4 |
+
transformers>=4.30.0
|