Mishal23 commited on
Commit
6d80f20
·
verified ·
1 Parent(s): 2ce4730

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -31
app.py CHANGED
@@ -1,23 +1,20 @@
1
- # app.py
2
-
3
- # Install necessary libraries (Run this separately in your environment if needed)
4
- # !pip install pandas sentence-transformers transformers datasets faiss-cpu gradio fastapi uvicorn
5
 
6
  # Import libraries
7
  import pandas as pd
8
- from sentence_transformers import SentenceTransformer
 
9
  import faiss
10
  from datasets import load_dataset
11
- from fastapi import FastAPI
12
  import gradio as gr
13
 
14
- # Initialize FastAPI app
15
- app = FastAPI()
16
-
17
  # Load the Dataset from Hugging Face and FAQ CSV
18
  support_data = load_dataset("rjac/e-commerce-customer-support-qa")
19
 
20
- # Load FAQ data from uploaded file (change as needed for local path)
 
 
21
  faq_data = pd.read_csv("Ecommerce_FAQs.csv")
22
 
23
  # Preprocess and Clean Data
@@ -66,24 +63,14 @@ def chatbot_interface(user_input):
66
  response = retrieve_answer(user_input)
67
  return f"Bot: {response}"
68
 
69
- # Define a route to serve the Gradio interface
70
- @app.get("/")
71
- def home():
72
- return {"message": "Welcome to the E-commerce Support Chatbot!"}
73
-
74
- # Launch Gradio Interface in a separate thread
75
- def launch_gradio():
76
- iface = gr.Interface(
77
- fn=chatbot_interface,
78
- inputs=gr.Textbox(lines=2, placeholder="Type your question here..."),
79
- outputs="text",
80
- title="E-commerce Support Chatbot",
81
- description="Ask questions about order tracking, returns, account help, and more!"
82
- )
83
- iface.launch(share=True)
84
-
85
- if __name__ == "__main__":
86
- import threading
87
- threading.Thread(target=launch_gradio).start()
88
- import uvicorn
89
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
+ # Install necessary libraries
2
+ #!pip install pandas sentence-transformers transformers datasets faiss-cpu gradio
 
 
3
 
4
  # Import libraries
5
  import pandas as pd
6
+ from sentence_transformers import SentenceTransformer, util
7
+ import torch
8
  import faiss
9
  from datasets import load_dataset
 
10
  import gradio as gr
11
 
 
 
 
12
  # Load the Dataset from Hugging Face and FAQ CSV
13
  support_data = load_dataset("rjac/e-commerce-customer-support-qa")
14
 
15
+ # Upload and load the FAQ data
16
+ from google.colab import files
17
+ uploaded = files.upload()
18
  faq_data = pd.read_csv("Ecommerce_FAQs.csv")
19
 
20
  # Preprocess and Clean Data
 
63
  response = retrieve_answer(user_input)
64
  return f"Bot: {response}"
65
 
66
+ # Set up Gradio Chat Interface
67
+ iface = gr.Interface(
68
+ fn=chatbot_interface,
69
+ inputs=gr.Textbox(lines=2, placeholder="Type your question here..."),
70
+ outputs="text",
71
+ title="E-commerce Support Chatbot",
72
+ description="Ask questions about order tracking, returns, account help, and more!"
73
+ )
74
+
75
+ # Launch the Interface
76
+ iface.launch(share=True)