Threatthriver commited on
Commit
b4aa9f9
Β·
verified Β·
1 Parent(s): 642bfad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import os
3
  import time
4
  from cerebras.cloud.sdk import Cerebras
 
5
 
6
  # Set up the Cerebras client
7
  client = Cerebras(api_key=os.getenv("CEREBRAS_API_KEY"))
@@ -37,19 +38,25 @@ def chat_with_cerebras(user_input, system_prompt, model, temperature, top_p, max
37
  if "Chain of Thought:" in chunk.choices[0].delta.content:
38
  chain_of_thought += chunk.choices[0].delta.content.split("Chain of Thought:", 1)[-1]
39
 
 
40
  # End compute time measurement
41
  compute_time = time.time() - start_time
42
 
43
- return response, chain_of_thought, f"Compute Time: {compute_time:.2f} seconds"
 
 
 
44
 
45
- except Exception as e:
46
- return f"Error: {str(e)}", "", "An error occurred. Please check your API key or the Cerebras service."
47
 
 
 
 
 
48
 
49
  # Gradio interface
50
  def gradio_ui():
51
  with gr.Blocks() as demo:
52
- gr.Markdown("""# πŸš€ IntellijMind: The Future of AI Chatbots\nExperience the most advanced chatbot for deep insights and unmatched clarity!""")
53
 
54
  with gr.Row():
55
  with gr.Column(scale=6):
@@ -58,26 +65,26 @@ def gradio_ui():
58
  compute_time = gr.Textbox(label="Compute Time", interactive=False)
59
  chain_of_thought_display = gr.Textbox(label="Chain of Thought", interactive=False, lines=10)
60
 
 
61
  user_input = gr.Textbox(label="Type your message", placeholder="Ask me anything...", lines=2)
62
  send_button = gr.Button("Send", variant="primary")
63
  clear_button = gr.Button("Clear Chat")
64
 
65
  # Set default values for system prompt, model, etc.
66
- default_system_prompt = "You are IntellijMind, an advanced AI designed to assist users with detailed insights, problem-solving, and chain-of-thought reasoning."
67
  default_model = "llama-3.3-70b"
68
  default_temperature = 0.2
69
  default_top_p = 1
70
  default_max_tokens = 1024
71
 
72
-
73
  def handle_chat(chat_history, user_input):
74
- chat_history.append((user_input, None)) # Add user message immediately
75
- yield chat_history, "", "Thinking..."
76
 
77
- ai_response, chain_of_thought, compute_info = chat_with_cerebras(user_input, default_system_prompt, default_model, default_temperature, default_top_p, default_max_tokens)
78
- chat_history[-1] = (user_input, ai_response) # Update the chatbot output with AI response
79
- yield chat_history, chain_of_thought, compute_info
80
 
 
 
81
 
82
  def clear_chat():
83
  return [], "", ""
@@ -88,13 +95,14 @@ def gradio_ui():
88
  inputs=[chat_history, user_input],
89
  outputs=[chat_history, chain_of_thought_display, compute_time]
90
  )
91
- clear_button.click(clear_chat, outputs=[chat_history, chain_of_thought_display, compute_time])
92
 
 
93
 
94
- gr.Markdown("""---\n### 🌟 Features:\n- **Advanced Reasoning**: Chain-of-thought explanations for complex queries.\n- **Real-Time Performance Metrics**: Measure response compute time instantly.\n- **Insightful Chain of Thought**: See the reasoning process behind AI decisions.\n- **User-Friendly Design**: Intuitive chatbot interface with powerful features.\n- **Powered by IntellijMind**: Setting new standards for AI interaction.\n""")
95
 
96
  return demo
97
 
 
98
  # Run the Gradio app
99
  demo = gradio_ui()
100
  demo.launch()
 
2
  import os
3
  import time
4
  from cerebras.cloud.sdk import Cerebras
5
+ import markdown
6
 
7
  # Set up the Cerebras client
8
  client = Cerebras(api_key=os.getenv("CEREBRAS_API_KEY"))
 
38
  if "Chain of Thought:" in chunk.choices[0].delta.content:
39
  chain_of_thought += chunk.choices[0].delta.content.split("Chain of Thought:", 1)[-1]
40
 
41
+
42
  # End compute time measurement
43
  compute_time = time.time() - start_time
44
 
45
+ # Improved formatting for chain of thought
46
+ formatted_response = response
47
+ if chain_of_thought:
48
+ formatted_response += f"\n\n**Chain of Thought:**\n{chain_of_thought}"
49
 
 
 
50
 
51
+ return formatted_response, chain_of_thought, f"Compute Time: {compute_time:.2f} seconds"
52
+
53
+ except Exception as e:
54
+ return f"Error: {str(e)}", "", "An error occurred. Please check your API key or the Cerebras service."
55
 
56
  # Gradio interface
57
  def gradio_ui():
58
  with gr.Blocks() as demo:
59
+ gr.Markdown("""# πŸš€ IntellijMind Release 1st \nExperience the most advanced chatbot for deep insights and unmatched clarity!""")
60
 
61
  with gr.Row():
62
  with gr.Column(scale=6):
 
65
  compute_time = gr.Textbox(label="Compute Time", interactive=False)
66
  chain_of_thought_display = gr.Textbox(label="Chain of Thought", interactive=False, lines=10)
67
 
68
+
69
  user_input = gr.Textbox(label="Type your message", placeholder="Ask me anything...", lines=2)
70
  send_button = gr.Button("Send", variant="primary")
71
  clear_button = gr.Button("Clear Chat")
72
 
73
  # Set default values for system prompt, model, etc.
74
+ default_system_prompt = "You are IntellijMind, an advanced AI designed to assist users with detailed insights, problem-solving, and chain-of-thought reasoning. Provide your answers in markdown format. If you do not know the answer, mention that you do not know and don't make things up."
75
  default_model = "llama-3.3-70b"
76
  default_temperature = 0.2
77
  default_top_p = 1
78
  default_max_tokens = 1024
79
 
 
80
  def handle_chat(chat_history, user_input):
81
+ chat_history.append((user_input, None))
82
+ yield chat_history, "", "Thinking..."
83
 
84
+ ai_response, chain_of_thought, compute_info = chat_with_cerebras(user_input, default_system_prompt, default_model, default_temperature, default_top_p, default_max_tokens)
 
 
85
 
86
+ chat_history[-1] = (user_input, markdown.markdown(ai_response)) # render markdown output to HTML
87
+ yield chat_history, chain_of_thought, compute_info
88
 
89
  def clear_chat():
90
  return [], "", ""
 
95
  inputs=[chat_history, user_input],
96
  outputs=[chat_history, chain_of_thought_display, compute_time]
97
  )
 
98
 
99
+ clear_button.click(clear_chat, outputs=[chat_history, chain_of_thought_display, compute_time])
100
 
101
+ gr.Markdown("""---\n### 🌟 Features:\n- **Advanced Reasoning**: Chain-of-thought explanations for complex queries.\n- **Real-Time Performance Metrics**: Measure response compute time instantly.\n- **Insightful Chain of Thought**: See the reasoning process behind AI decisions.\n- **User-Friendly Design**: Intuitive chatbot interface with powerful features.\n- **Powered by IntellijMind Release 1st**: Setting new standards for AI interaction.\n""")
102
 
103
  return demo
104
 
105
+
106
  # Run the Gradio app
107
  demo = gradio_ui()
108
  demo.launch()