tanya17 commited on
Commit
b20b57e
·
verified ·
1 Parent(s): 877f12a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -13,6 +13,10 @@ import plotly.express as px
13
  import time
14
  import threading
15
  import random
 
 
 
 
16
 
17
  # Database setup for user authentication
18
  def init_db():
@@ -208,6 +212,18 @@ def generate_dashboard():
208
  title='Sustainability Score vs. Product Price')
209
  return lifecycle_fig, price_trend_fig, engagement_fig, sustainability_fig
210
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  # Gradio Interfaces
212
  with gr.Blocks() as app:
213
  gr.Markdown("# 🔐 Circular Economy Marketplace")
@@ -268,6 +284,11 @@ with gr.Blocks() as app:
268
  ]
269
  dashboard_btn = gr.Button("Generate Dashboard")
270
  dashboard_btn.click(generate_dashboard, inputs=[], outputs=dashboard_outputs)
 
 
 
 
 
271
 
272
  # Simulate real-time data updates
273
  def live_update():
 
13
  import time
14
  import threading
15
  import random
16
+ import openai
17
+
18
+ # Replace with your OpenAI API key
19
+ openai.api_key = "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"
20
 
21
  # Database setup for user authentication
22
  def init_db():
 
212
  title='Sustainability Score vs. Product Price')
213
  return lifecycle_fig, price_trend_fig, engagement_fig, sustainability_fig
214
 
215
+ # Define chatbot function
216
+ def chatbot_response(user_input):
217
+ try:
218
+ response = openai.ChatCompletion.create(
219
+ model="gpt-4",
220
+ messages=[{"role": "system", "content": "You are an AI expert in circular economy and sustainable product recommendations."},
221
+ {"role": "user", "content": user_input}]
222
+ )
223
+ return response["choices"][0]["message"]["content"]
224
+ except Exception as e:
225
+ return f"Error: {str(e)}"
226
+
227
  # Gradio Interfaces
228
  with gr.Blocks() as app:
229
  gr.Markdown("# 🔐 Circular Economy Marketplace")
 
284
  ]
285
  dashboard_btn = gr.Button("Generate Dashboard")
286
  dashboard_btn.click(generate_dashboard, inputs=[], outputs=dashboard_outputs)
287
+ with gr.Tab("AI Chatbot"):
288
+ chatbot_input = gr.Textbox(label="Ask me anything about circular economy, product lifecycle, dynamic pricing, and recommendations!")
289
+ chatbot_output = gr.Textbox(label="AI Response")
290
+ chatbot_btn = gr.Button("Ask")
291
+ chatbot_btn.click(chatbot_response, inputs=chatbot_input, outputs=chatbot_output)
292
 
293
  # Simulate real-time data updates
294
  def live_update():