yasserrmd commited on
Commit
8068acd
·
verified ·
1 Parent(s): eb58fe8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -8,38 +8,39 @@ client = openai.OpenAI(
8
  base_url="https://api.sambanova.ai/v1",
9
  )
10
 
11
- def generate_code_haiku(theme):
12
  """
13
- Generates a code-themed haiku based on the input theme.
14
  """
15
  prompt = (
16
- f"Write a poetic haiku about coding with the theme: '{theme}'. "
17
- "Focus on creativity and programming metaphors."
 
18
  )
19
 
20
  try:
21
  response = client.chat.completions.create(
22
- model='Meta-Llama-3.1-8B-Instruct',
23
  messages=[
24
- {"role": "system", "content": "You are a creative haiku generator for coding themes."},
25
  {"role": "user", "content": prompt}
26
  ],
27
  temperature=0.7,
28
  top_p=0.9
29
  )
30
- haiku = response.choices[0].message.content.strip()
31
- return haiku
32
  except Exception as e:
33
- return f"Error generating haiku: {str(e)}"
34
 
35
  # Gradio Interface
36
  def gradio_interface():
37
  interface = gr.Interface(
38
- fn=generate_code_haiku,
39
- inputs=gr.Textbox(label="Theme (e.g., Debugging, Algorithms, AI, etc.)"),
40
- outputs=gr.Textbox(label="Generated Code Haiku"),
41
- title="Code Haiku Generator",
42
- description="Generate poetic haikus about programming themes. Enter a theme, and let the AI craft a haiku for you!",
43
  )
44
  return interface
45
 
 
8
  base_url="https://api.sambanova.ai/v1",
9
  )
10
 
11
+ def generate_haiku_comment(code):
12
  """
13
+ Generates a haiku comment for the given code snippet.
14
  """
15
  prompt = (
16
+ f"Analyze the following code and write a poetic haiku as a comment summarizing its purpose or essence:\n\n"
17
+ f"{code}\n\n"
18
+ "Focus on creativity and capturing the core idea."
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 for code comments."},
26
  {"role": "user", "content": prompt}
27
  ],
28
  temperature=0.7,
29
  top_p=0.9
30
  )
31
+ haiku_comment = response.choices[0].message.content.strip()
32
+ return haiku_comment
33
  except Exception as e:
34
+ return f"Error generating haiku comment: {str(e)}"
35
 
36
  # Gradio Interface
37
  def gradio_interface():
38
  interface = gr.Interface(
39
+ fn=generate_haiku_comment,
40
+ inputs=gr.Textbox(label="Code Snippet"),
41
+ outputs=gr.Textbox(label="Generated Haiku Comment"),
42
+ title="Code Haiku Comment Generator",
43
+ description="Paste a code snippet, and let the AI generate a poetic haiku comment summarizing it!",
44
  )
45
  return interface
46