decodingdatascience commited on
Commit
cf2d334
Β·
verified Β·
1 Parent(s): 66ac949

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -75,12 +75,12 @@ def process_input(input_type: str, query: str) -> Tuple[str, str]:
75
  """Process user input and return AI response."""
76
  if not query.strip():
77
  return "", "Please enter a query"
78
-
79
  if input_type == "brainstorm":
80
  response = assistant.brainstorm_project(query)
81
  else:
82
  response = assistant.get_code_suggestion(query)
83
-
84
  if response["success"]:
85
  status = f"Success! Tokens used: {response.get('tokens_used', 'N/A')}"
86
  return response["content"], status
@@ -91,9 +91,8 @@ def handle_project_click(project_name: str) -> Tuple[str, str, str]:
91
  """Handle when a project option is clicked."""
92
  description = PROJECT_OPTIONS[project_name]
93
  response = assistant.brainstorm_project(description)
94
-
95
  if response["success"]:
96
- status = f"Success! Tokens used: {response.get('tokens_used', 'N/A')}"
97
  return "brainstorm", description, response["content"]
98
  else:
99
  return "brainstorm", description, f"Error: {response.get('error', 'Unknown error occurred')}"
@@ -107,7 +106,7 @@ with gr.Blocks(css=CUSTOM_CSS, title="DDS AI Project Assistant") as interface:
107
  <p class="subtitle">Your Generative AI Project Development Companion</p>
108
  </div>
109
  """)
110
-
111
  with gr.Row():
112
  # Left sidebar with project options
113
  with gr.Column(scale=1, elem_classes="sidebar"):
@@ -116,13 +115,12 @@ with gr.Blocks(css=CUSTOM_CSS, title="DDS AI Project Assistant") as interface:
116
  🎯 Popular GenAI Projects
117
  </h3>
118
  """)
119
- project_buttons = [
120
- gr.Button(
121
- name,
122
- elem_classes="project-button"
123
- ) for name in PROJECT_OPTIONS.keys()
124
- ]
125
-
126
  # Main content area
127
  with gr.Column(scale=3):
128
  input_type = gr.Radio(
@@ -130,18 +128,18 @@ with gr.Blocks(css=CUSTOM_CSS, title="DDS AI Project Assistant") as interface:
130
  label="πŸ€” What kind of help do you need?",
131
  value="brainstorm"
132
  )
133
-
134
  query = gr.Textbox(
135
  label="πŸ’­ Enter your topic or code request",
136
  placeholder="e.g., 'text-to-image generation' or 'implement stable diffusion'",
137
  elem_classes="output-box"
138
  )
139
-
140
  submit_btn = gr.Button(
141
  "πŸš€ Get AI Assistance",
142
  elem_classes="project-button"
143
  )
144
-
145
  with gr.Column(elem_classes="output-box"):
146
  output = gr.Textbox(
147
  label="πŸ€– AI Response",
@@ -150,27 +148,29 @@ with gr.Blocks(css=CUSTOM_CSS, title="DDS AI Project Assistant") as interface:
150
  status = gr.Textbox(
151
  label="πŸ“Š Status"
152
  )
153
-
154
  gr.HTML("""
155
  <div style="text-align: center; margin-top: 20px; padding: 10px; border-top: 2px solid #264653;">
156
  <p>Developed by DDS Team | Powered by OpenAI</p>
157
  </div>
158
  """)
159
-
160
  # Handle main submit button
161
  submit_btn.click(
162
  fn=process_input,
163
  inputs=[input_type, query],
164
  outputs=[output, status]
165
  )
166
-
167
- # Handle project option buttons
168
- for btn in project_buttons:
 
 
169
  btn.click(
170
- fn=handle_project_click,
171
- inputs=[btn],
172
  outputs=[input_type, query, output]
173
  )
174
 
175
  if __name__ == "__main__":
176
- interface.launch()
 
75
  """Process user input and return AI response."""
76
  if not query.strip():
77
  return "", "Please enter a query"
78
+
79
  if input_type == "brainstorm":
80
  response = assistant.brainstorm_project(query)
81
  else:
82
  response = assistant.get_code_suggestion(query)
83
+
84
  if response["success"]:
85
  status = f"Success! Tokens used: {response.get('tokens_used', 'N/A')}"
86
  return response["content"], status
 
91
  """Handle when a project option is clicked."""
92
  description = PROJECT_OPTIONS[project_name]
93
  response = assistant.brainstorm_project(description)
94
+
95
  if response["success"]:
 
96
  return "brainstorm", description, response["content"]
97
  else:
98
  return "brainstorm", description, f"Error: {response.get('error', 'Unknown error occurred')}"
 
106
  <p class="subtitle">Your Generative AI Project Development Companion</p>
107
  </div>
108
  """)
109
+
110
  with gr.Row():
111
  # Left sidebar with project options
112
  with gr.Column(scale=1, elem_classes="sidebar"):
 
115
  🎯 Popular GenAI Projects
116
  </h3>
117
  """)
118
+ # Keep (name, button) pairs so we can wire up clicks correctly below
119
+ project_buttons = []
120
+ for name in PROJECT_OPTIONS.keys():
121
+ btn = gr.Button(name, elem_classes="project-button")
122
+ project_buttons.append((name, btn))
123
+
 
124
  # Main content area
125
  with gr.Column(scale=3):
126
  input_type = gr.Radio(
 
128
  label="πŸ€” What kind of help do you need?",
129
  value="brainstorm"
130
  )
131
+
132
  query = gr.Textbox(
133
  label="πŸ’­ Enter your topic or code request",
134
  placeholder="e.g., 'text-to-image generation' or 'implement stable diffusion'",
135
  elem_classes="output-box"
136
  )
137
+
138
  submit_btn = gr.Button(
139
  "πŸš€ Get AI Assistance",
140
  elem_classes="project-button"
141
  )
142
+
143
  with gr.Column(elem_classes="output-box"):
144
  output = gr.Textbox(
145
  label="πŸ€– AI Response",
 
148
  status = gr.Textbox(
149
  label="πŸ“Š Status"
150
  )
151
+
152
  gr.HTML("""
153
  <div style="text-align: center; margin-top: 20px; padding: 10px; border-top: 2px solid #264653;">
154
  <p>Developed by DDS Team | Powered by OpenAI</p>
155
  </div>
156
  """)
157
+
158
  # Handle main submit button
159
  submit_btn.click(
160
  fn=process_input,
161
  inputs=[input_type, query],
162
  outputs=[output, status]
163
  )
164
+
165
+ # Handle project option buttons.
166
+ # A Button has no value to pass as an input, so we capture the project
167
+ # name in a default argument (n=name) and feed it to the handler directly.
168
+ for name, btn in project_buttons:
169
  btn.click(
170
+ fn=lambda n=name: handle_project_click(n),
171
+ inputs=None,
172
  outputs=[input_type, query, output]
173
  )
174
 
175
  if __name__ == "__main__":
176
+ interface.launch()