Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,67 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
# Validate GitHub URL format
|
7 |
-
regex = r"^(https?:\/\/)?(www\.)?github\.com\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$"
|
8 |
-
if not re.match(regex, url):
|
9 |
-
return "Invalid URL", None
|
10 |
-
|
11 |
-
# Mocked report
|
12 |
-
report = {
|
13 |
-
"code_quality": "Good",
|
14 |
-
"potential_bugs": "2",
|
15 |
-
"areas_for_improvement": "Code documentation, test coverage"
|
16 |
-
}
|
17 |
-
|
18 |
-
return "Valid URL", report
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
if report is None:
|
26 |
-
return validation_message, None
|
27 |
-
|
28 |
-
# Return validation and the mocked analysis report
|
29 |
-
return validation_message, report
|
30 |
|
31 |
-
# Create Gradio interface
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
url_input = gr.Textbox(
|
38 |
-
label="GitHub Repository URL",
|
39 |
-
placeholder="https://github.com/username/repository"
|
40 |
-
)
|
41 |
-
|
42 |
-
# Output for validation message
|
43 |
-
validation_output = gr.Textbox(label="Validation Status", interactive=False)
|
44 |
-
|
45 |
-
# Output for the analysis report
|
46 |
-
report_output = gr.Column(
|
47 |
-
visible=False,
|
48 |
-
children=[
|
49 |
-
gr.Markdown("### Analysis Report"),
|
50 |
-
gr.Textbox(label="Code Quality", interactive=False),
|
51 |
-
gr.Textbox(label="Potential Bugs", interactive=False),
|
52 |
-
gr.Textbox(label="Areas for Improvement", interactive=False),
|
53 |
-
]
|
54 |
-
)
|
55 |
-
|
56 |
-
# Submit button and event handling
|
57 |
-
submit_btn = gr.Button("Analyze")
|
58 |
-
|
59 |
-
# Set up the interaction logic
|
60 |
-
submit_btn.click(
|
61 |
-
github_analysis,
|
62 |
-
inputs=url_input,
|
63 |
-
outputs=[validation_output, report_output]
|
64 |
-
)
|
65 |
-
|
66 |
-
# Launch the interface
|
67 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize the code generation pipeline
|
5 |
+
generator = pipeline('code-generation', model='Salesforce/codegen-350M-mono')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def generate_code(prompt, max_length=128):
|
8 |
+
"""Generates code based on the given prompt."""
|
9 |
+
result = generator(prompt, max_length=max_length)
|
10 |
+
return result[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Create the Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=generate_code,
|
15 |
+
inputs=[
|
16 |
+
gr.Textbox(lines=5, placeholder="Enter your code prompt here..."),
|
17 |
+
gr.Slider(minimum=64, maximum=512, step=8, value=128, label="Max Length")
|
18 |
+
],
|
19 |
+
outputs=gr.Code(language="python"),
|
20 |
+
title="π€ Code Generation Demo",
|
21 |
+
description="Generate code using an open-source language model."
|
22 |
+
)
|
23 |
|
24 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|