Update app.py
Browse files
app.py
CHANGED
|
@@ -12,17 +12,19 @@ def generate_haiku_comment(code):
|
|
| 12 |
"""
|
| 13 |
Generates a haiku comment for the given code snippet.
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
f"Analyze the following code and
|
| 17 |
-
f"
|
| 18 |
-
"
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
try:
|
| 22 |
response = client.chat.completions.create(
|
| 23 |
model='Qwen2.5-Coder-32B-Instruct',
|
| 24 |
messages=[
|
| 25 |
-
{"role": "system", "content": "You are a creative haiku generator
|
| 26 |
{"role": "user", "content": prompt}
|
| 27 |
],
|
| 28 |
temperature=0.7,
|
|
@@ -37,8 +39,10 @@ def generate_haiku_comment(code):
|
|
| 37 |
def gradio_interface():
|
| 38 |
interface = gr.Interface(
|
| 39 |
fn=generate_haiku_comment,
|
| 40 |
-
inputs=gr.Textbox(label="Code Snippet"),
|
| 41 |
-
outputs=gr.
|
|
|
|
|
|
|
| 42 |
title="Code Haiku Comment Generator",
|
| 43 |
description="Paste a code snippet, and let the AI generate a poetic haiku comment summarizing it!",
|
| 44 |
)
|
|
|
|
| 12 |
"""
|
| 13 |
Generates a haiku comment for the given code snippet.
|
| 14 |
"""
|
| 15 |
+
prompt = (
|
| 16 |
+
f"Analyze the following code and perform two tasks:\n\n"
|
| 17 |
+
f"1. Write a poetic haiku as a comment summarizing its purpose or essence.\n"
|
| 18 |
+
f"2. Refactor and clean the code while maintaining its functionality.\n\n"
|
| 19 |
+
f"Code:\n{code}\n\n"
|
| 20 |
+
"Provide the output as haiku comment followed by the refactored code."
|
| 21 |
)
|
| 22 |
|
| 23 |
try:
|
| 24 |
response = client.chat.completions.create(
|
| 25 |
model='Qwen2.5-Coder-32B-Instruct',
|
| 26 |
messages=[
|
| 27 |
+
{"role": "system", "content": "You are a creative haiku generator and code refactoring assistant."},
|
| 28 |
{"role": "user", "content": prompt}
|
| 29 |
],
|
| 30 |
temperature=0.7,
|
|
|
|
| 39 |
def gradio_interface():
|
| 40 |
interface = gr.Interface(
|
| 41 |
fn=generate_haiku_comment,
|
| 42 |
+
inputs=gr.Textbox(label="Code Snippet",lines=10, placeholder="Paste your code snippet here..."),
|
| 43 |
+
outputs= gr.Markdown( """
|
| 44 |
+
Code will be generated here
|
| 45 |
+
"""),
|
| 46 |
title="Code Haiku Comment Generator",
|
| 47 |
description="Paste a code snippet, and let the AI generate a poetic haiku comment summarizing it!",
|
| 48 |
)
|