tanya17 commited on
Commit
fe038cc
·
verified ·
1 Parent(s): 92a532f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -12
app.py CHANGED
@@ -16,7 +16,7 @@ import requests
16
  import os # Import the os module to access environment variables
17
 
18
  # Hugging Face API configuration
19
- HUGGINGFACE_API_URL = "https://router.huggingface.co/hf-inference/models/google-bert/bert-base-multilingual-cased" # Corrected URL
20
  HUGGINGFACE_API_KEY = os.environ["HUGGINGFACE_API_KEY"] # Access the API key from environment variables
21
 
22
  # Hugging Face Chatbot Function
@@ -243,23 +243,74 @@ with gr.Blocks() as app:
243
  """)
244
  gr.Markdown("# 🔐 Circular Economy Marketplace")
245
 
246
- # Existing tabs (Login/Register, Product Lifecycle Prediction, etc.)
247
  with gr.Tab("Login/Register"):
248
- # ... (existing code)
249
-
 
 
 
 
 
 
 
 
 
 
 
 
250
  with gr.Tab("Product Lifecycle Prediction"):
251
- # ... (existing code)
252
-
 
 
 
 
 
 
 
 
 
 
 
 
253
  with gr.Tab("Dynamic Pricing"):
254
- # ... (existing code)
255
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  with gr.Tab("Product Recommendation"):
257
- # ... (existing code)
 
 
 
258
 
 
259
  with gr.Tab("Circular Economy Analytics"):
260
- # ... (existing code)
261
-
262
- # Add a new tab for the Hugging Face Chatbot
 
 
 
 
 
 
 
263
  with gr.Tab("AI Chatbot"):
264
  gr.Markdown("""
265
  <div style="text-align: center;">
 
16
  import os # Import the os module to access environment variables
17
 
18
  # Hugging Face API configuration
19
+ HUGGINGFACE_API_URL = "https://api-inference.huggingface.co/models/gpt2" # Replace with the desired model
20
  HUGGINGFACE_API_KEY = os.environ["HUGGINGFACE_API_KEY"] # Access the API key from environment variables
21
 
22
  # Hugging Face Chatbot Function
 
243
  """)
244
  gr.Markdown("# 🔐 Circular Economy Marketplace")
245
 
246
+ # Login/Register Tab
247
  with gr.Tab("Login/Register"):
248
+ with gr.Tab("Register"):
249
+ reg_username = gr.Textbox(label="Username")
250
+ reg_password = gr.Textbox(label="Password", type="password")
251
+ reg_btn = gr.Button("Register")
252
+ reg_output = gr.Textbox()
253
+ reg_btn.click(register, inputs=[reg_username, reg_password], outputs=reg_output)
254
+ with gr.Tab("Login"):
255
+ log_username = gr.Textbox(label="Username")
256
+ log_password = gr.Textbox(label="Password", type="password")
257
+ log_btn = gr.Button("Login")
258
+ log_output = gr.Textbox()
259
+ log_btn.click(login, inputs=[log_username, log_password], outputs=log_output)
260
+
261
+ # Product Lifecycle Prediction Tab
262
  with gr.Tab("Product Lifecycle Prediction"):
263
+ lifecycle_inputs = [
264
+ gr.Dropdown(["Plastic", "Metal", "Wood", "Composite", "Electronics"], label="Category"),
265
+ gr.Textbox(label="Product Name"),
266
+ gr.Number(label="Price"),
267
+ gr.Number(label="Rating"),
268
+ gr.Number(label="NumReviews"),
269
+ gr.Number(label="StockQuantity"),
270
+ gr.Number(label="Discount")
271
+ ]
272
+ lifecycle_output = gr.Textbox(label="Prediction")
273
+ lifecycle_btn = gr.Button("Predict")
274
+ lifecycle_btn.click(predict_lifecycle, inputs=lifecycle_inputs, outputs=lifecycle_output)
275
+
276
+ # Dynamic Pricing Tab
277
  with gr.Tab("Dynamic Pricing"):
278
+ pricing_inputs = [
279
+ gr.Dropdown(["iPhone 13", "Nike Shoes", "Samsung TV", "Adidas Jacket", "Dell Laptop", "Sony Headphones", "Apple Watch",
280
+ "LG Refrigerator", "HP Printer", "Bose Speaker"], label="Product Name"),
281
+ gr.Dropdown(["Electronics", "Fashion", "Home Appliances"], label="Category"),
282
+ gr.Number(label="Base Price"),
283
+ gr.Number(label="Competitor Price"),
284
+ gr.Dropdown(["Low", "Medium", "High"], label="Demand"),
285
+ gr.Number(label="Stock"),
286
+ gr.Number(label="Reviews"),
287
+ gr.Number(label="Rating"),
288
+ gr.Dropdown(["Holiday", "Summer", "Winter", "Off-season"], label="Season"),
289
+ gr.Number(label="Discount (%)")
290
+ ]
291
+ pricing_output = gr.Textbox(label="Predicted Price")
292
+ pricing_btn = gr.Button("Predict")
293
+ pricing_btn.click(predict_price, inputs=pricing_inputs, outputs=pricing_output)
294
+
295
+ # Product Recommendation Tab
296
  with gr.Tab("Product Recommendation"):
297
+ recommendation_input = gr.Dropdown(choices=df_recommendation['category'].unique().tolist(), label="Select Product Category")
298
+ recommendation_output = gr.Dataframe()
299
+ recommendation_btn = gr.Button("Recommend")
300
+ recommendation_btn.click(recommend_products, inputs=recommendation_input, outputs=recommendation_output)
301
 
302
+ # Circular Economy Analytics Tab
303
  with gr.Tab("Circular Economy Analytics"):
304
+ dashboard_outputs = [
305
+ gr.Plot(label="Product Lifecycle Analytics"),
306
+ gr.Plot(label="Dynamic Pricing Insights"),
307
+ gr.Plot(label="User Engagement Trends"),
308
+ gr.Plot(label="Sustainability & Recycling Insights")
309
+ ]
310
+ dashboard_btn = gr.Button("Generate Dashboard")
311
+ dashboard_btn.click(generate_dashboard, inputs=[], outputs=dashboard_outputs)
312
+
313
+ # AI Chatbot Tab
314
  with gr.Tab("AI Chatbot"):
315
  gr.Markdown("""
316
  <div style="text-align: center;">