SatyamSinghal commited on
Commit
0fd1b32
·
verified ·
1 Parent(s): 2f9eb1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -52
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import gradio as gr
2
  import openai
 
3
  import os
4
 
 
5
  # Set up OpenAI API with custom Groq endpoint
6
  openai.api_key = os.getenv("PrepBuddy_API_KEY")
7
  openai.api_base = "https://api.groq.com/openai/v1"
@@ -9,6 +11,7 @@ openai.api_base = "https://api.groq.com/openai/v1"
9
  # Function to get the Groq model's response
10
  def get_groq_response(message, mode):
11
  try:
 
12
  motivational_message = (
13
  "Keep pushing forward! You've got this. Programming might seem tough at first, but every step you take "
14
  "is one step closer to mastering it. Let's score 70 on 70 in programming together!"
@@ -66,7 +69,7 @@ def chatbot(user_input, output_format, history=[]):
66
  except Exception as e:
67
  return [(user_input, f"Error: {str(e)}")], history
68
 
69
- # Gradio Interface setup with custom HTML, CSS, and JS for UI
70
  chat_interface = gr.Interface(
71
  fn=chatbot, # Function to call for chatbot interaction
72
  inputs=[
@@ -78,10 +81,7 @@ chat_interface = gr.Interface(
78
  ),
79
  "state" # Chat history
80
  ],
81
- outputs=[
82
- gr.HTML("<div id='chat-box'></div>"), # Placeholder for chat output
83
- "state" # Updated history
84
- ],
85
  live=False, # Disable live chat, responses shown after submit
86
  title="GS C PrepBuddy", # Title of the app
87
  description=(
@@ -90,54 +90,10 @@ chat_interface = gr.Interface(
90
  "Choose your output format—Code, Flowchart, Algorithm, or Exam Preparation.\n\n"
91
  "Ask your query, and I'll guide you every step of the way!\n\n"
92
  "Made by Satyam Singhal"
93
- ),
94
- # Adding custom CSS and JS for better UI interaction
95
- css="""
96
- #chat-box {
97
- background-color: rgba(223, 242, 247, .5);
98
- padding: 20px;
99
- border-radius: 10px;
100
- height: 400px;
101
- overflow-y: scroll;
102
- font-family: Arial, sans-serif;
103
- font-size: 14px;
104
- width: 100%;
105
- }
106
-
107
- .user-message {
108
- background-color: #4CAF50;
109
- color: white;
110
- padding: 10px;
111
- border-radius: 5px;
112
- margin-bottom: 10px;
113
- }
114
-
115
- .bot-response {
116
- background-color: #2196F3;
117
- color: white;
118
- padding: 10px;
119
- border-radius: 5px;
120
- margin-bottom: 10px;
121
- }
122
-
123
- #input-text {
124
- margin-top: 20px;
125
- }
126
- """,
127
- js="""
128
- function updateChatBox(userInput, botResponse) {
129
- const chatBox = document.getElementById('chat-box');
130
- chatBox.innerHTML += '<div class="user-message">' + userInput + '</div>';
131
- chatBox.innerHTML += '<div class="bot-response">' + botResponse + '</div>';
132
- chatBox.scrollTop = chatBox.scrollHeight; // Auto-scroll to the bottom
133
- }
134
-
135
- function handleChat(userInput, outputFormat) {
136
- gradioApp().querySelector('.gr-button').click(); // Simulate submit button click
137
- }
138
- """
139
  )
140
 
141
  # Launch the Gradio interface
142
  if __name__ == "__main__":
143
- chat_interface.launch()
 
 
1
  import gradio as gr
2
  import openai
3
+ import langdetect as detect
4
  import os
5
 
6
+
7
  # Set up OpenAI API with custom Groq endpoint
8
  openai.api_key = os.getenv("PrepBuddy_API_KEY")
9
  openai.api_base = "https://api.groq.com/openai/v1"
 
11
  # Function to get the Groq model's response
12
  def get_groq_response(message, mode):
13
  try:
14
+ # Use a system prompt tailored to the selected mode
15
  motivational_message = (
16
  "Keep pushing forward! You've got this. Programming might seem tough at first, but every step you take "
17
  "is one step closer to mastering it. Let's score 70 on 70 in programming together!"
 
69
  except Exception as e:
70
  return [(user_input, f"Error: {str(e)}")], history
71
 
72
+ # Gradio Interface setup
73
  chat_interface = gr.Interface(
74
  fn=chatbot, # Function to call for chatbot interaction
75
  inputs=[
 
81
  ),
82
  "state" # Chat history
83
  ],
84
+ outputs=["chatbot", "state"], # Outputs: the chat and updated history (state)
 
 
 
85
  live=False, # Disable live chat, responses shown after submit
86
  title="GS C PrepBuddy", # Title of the app
87
  description=(
 
90
  "Choose your output format—Code, Flowchart, Algorithm, or Exam Preparation.\n\n"
91
  "Ask your query, and I'll guide you every step of the way!\n\n"
92
  "Made by Satyam Singhal"
93
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  )
95
 
96
  # Launch the Gradio interface
97
  if __name__ == "__main__":
98
+ chat_interface.launch()
99
+