Naz786 commited on
Commit
7702100
·
verified ·
1 Parent(s): b36d2b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -19
app.py CHANGED
@@ -78,6 +78,16 @@ if not GROQ_API_KEY:
78
  st.stop()
79
  client = Groq(api_key=GROQ_API_KEY)
80
 
 
 
 
 
 
 
 
 
 
 
81
  def groq_api_call(prompt):
82
  chat_completion = client.chat.completions.create(
83
  messages=[{"role": "user", "content": prompt}],
@@ -85,6 +95,13 @@ def groq_api_call(prompt):
85
  )
86
  return chat_completion.choices[0].message.content
87
 
 
 
 
 
 
 
 
88
  def get_diff_html(original, modified):
89
  original_lines = original.splitlines()
90
  modified_lines = modified.splitlines()
@@ -246,6 +263,8 @@ if "timeline" not in st.session_state:
246
  st.session_state.timeline = []
247
  if "suggestions" not in st.session_state:
248
  st.session_state.suggestions = []
 
 
249
 
250
  col1, col2 = st.columns([2, 3], gap="large")
251
 
@@ -313,24 +332,19 @@ with col2:
313
  st.session_state.suggestions = suggestions
314
  st.success("Agentic workflow complete. See timeline below.")
315
 
316
- if st.session_state.timeline:
317
- for i, step in enumerate(st.session_state.timeline):
318
- with st.expander(f"Step {i+1}: {step['step']}"):
319
- st.markdown(f"<b>{step['description']}</b>", unsafe_allow_html=True)
320
- if step['step'] in ["Refactor", "Test Generation"]:
321
- if i > 0:
322
- prev_code = st.session_state.timeline[i-1]['code']
323
- diff_html = get_diff_html(prev_code, step['code'])
324
- st.markdown("**Side-by-Side Diff:**")
325
- st.components.v1.html(diff_html, height=400, scrolling=True)
326
- if step['step'] in ["Refactor", "Test Generation"]:
327
- st.markdown("**Code Output:**")
328
- st.code(step['output'], language=programming_language.lower())
329
- else:
330
- st.markdown("**Output:**")
331
- st.write(step['output'])
332
- else:
333
- st.info("Run the agentic workflow to see step-by-step results, explanations, and code evolution.")
334
 
335
  st.markdown("---")
336
- st.markdown('<div style="text-align: center; color: #22304a; font-size: 1rem; margin-top: 2em;">Powered by <b>BLACKBOX.AI</b></div>', unsafe_allow_html=True)
 
78
  st.stop()
79
  client = Groq(api_key=GROQ_API_KEY)
80
 
81
+ # --- Blackbox AI Agent Setup ---
82
+ BLACKBOX_API_KEY = os.environ.get("BLACKBOX_API_KEY")
83
+ if not BLACKBOX_API_KEY:
84
+ st.error("BLACKBOX_API_KEY environment variable not set. Please set it in your Hugging Face Space secrets.")
85
+ st.stop()
86
+
87
+ # Chat history management
88
+ if "chat_history" not in st.session_state:
89
+ st.session_state.chat_history = []
90
+
91
  def groq_api_call(prompt):
92
  chat_completion = client.chat.completions.create(
93
  messages=[{"role": "user", "content": prompt}],
 
95
  )
96
  return chat_completion.choices[0].message.content
97
 
98
+ def blackbox_ai_call(messages):
99
+ # This is a placeholder for actual Blackbox AI API call using BLACKBOX_API_KEY
100
+ # For demonstration, we simulate a response by echoing last user message
101
+ last_user_message = messages[-1]["content"] if messages else ""
102
+ response = f"Blackbox AI response to: {last_user_message}"
103
+ return response
104
+
105
  def get_diff_html(original, modified):
106
  original_lines = original.splitlines()
107
  modified_lines = modified.splitlines()
 
263
  st.session_state.timeline = []
264
  if "suggestions" not in st.session_state:
265
  st.session_state.suggestions = []
266
+ if "chat_history" not in st.session_state:
267
+ st.session_state.chat_history = []
268
 
269
  col1, col2 = st.columns([2, 3], gap="large")
270
 
 
332
  st.session_state.suggestions = suggestions
333
  st.success("Agentic workflow complete. See timeline below.")
334
 
335
+ # Chatbox with history using Blackbox AI agent
336
+ st.subheader("Chat with Blackbox AI Agent")
337
+ user_input = st.text_input("Enter your message:", key="chat_input")
338
+ if user_input:
339
+ st.session_state.chat_history.append({"role": "user", "content": user_input})
340
+ response = blackbox_ai_call(st.session_state.chat_history)
341
+ st.session_state.chat_history.append({"role": "assistant", "content": response})
342
+
343
+ for chat in st.session_state.chat_history:
344
+ if chat["role"] == "user":
345
+ st.markdown(f"**You:** {chat['content']}")
346
+ else:
347
+ st.markdown(f"**Blackbox AI:** {chat['content']}")
 
 
 
 
 
348
 
349
  st.markdown("---")
350
+ st.markdown('<div style="text-align: center; color: #22304a; font-size: 1rem; margin-top: 2em;">Powered by <b>BLACKBOX.AI</b></div>', unsafe_allow_html=True)