subashdvorak commited on
Commit
d2353f4
·
verified ·
1 Parent(s): 72e9b94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -46
app.py CHANGED
@@ -1,46 +1,46 @@
1
- import pandas as pd
2
- from langchain_groq import ChatGroq
3
- from langchain_experimental.agents.agent_toolkits import create_csv_agent
4
- import gradio as gr
5
-
6
- # Reading a CSV file
7
- csv_file_path = '/content/final_dataset.csv'
8
- df_csv = pd.read_csv(csv_file_path)
9
-
10
- # Initialize the Groq API and the LLM
11
- groq_api = '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'
12
- llm = ChatGroq(temperature=0, model="llama3-70b-8192", api_key=groq_api)
13
-
14
- # Create the CSV agent
15
- agent = create_csv_agent(llm, csv_file_path, verbose=True, allow_dangerous_code=True, handle_parsing_errors=True)
16
-
17
- # Function to query data
18
- def query_data(query):
19
- response = agent.invoke(query)
20
- return response
21
-
22
- # Function for Gradio interface
23
- def get_recommendations(user_query):
24
- additional_query = '''If you can't find the exact response from the dataframe, you can give the responses similar to the query.
25
- If you recommend some places, give their descriptions too in a paragraph.
26
- While giving descriptions, give from the reviews of that place in more than 30 words.
27
- If there are 'hotels' in the query, recommend hotels only not the restaurants and adventures. And same for other place types.
28
- Give their revel ratings too.
29
- Don't try give the descriptions that are not provided in the dataframe.
30
- Try to minimize giving the same descriptions for more than one places. '''
31
-
32
- full_query = f"{user_query} {additional_query}"
33
- response = query_data(full_query)
34
- return response['output']
35
-
36
- # Create Gradio interface
37
- iface = gr.Interface(
38
- fn=get_recommendations,
39
- inputs=gr.Textbox(label="Ask your query about hotels:", placeholder="Type your query here..."),
40
- outputs=gr.Textbox(label="Response will appear here."),
41
- title="Hotel and Restaurant Recommendation System",
42
- description="Ask for recommendations based on the data in the CSV file."
43
- )
44
-
45
- # Launch the Gradio app
46
- iface.launch(share=True)
 
1
+ import pandas as pd
2
+ from langchain_groq import ChatGroq
3
+ from langchain_experimental.agents.agent_toolkits import create_csv_agent
4
+ import gradio as gr
5
+
6
+ # Reading a CSV file
7
+ csv_file_path = 'final_dataset.csv'
8
+ df_csv = pd.read_csv(csv_file_path)
9
+
10
+ # Initialize the Groq API and the LLM
11
+ groq_api = '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'
12
+ llm = ChatGroq(temperature=0, model="llama3-70b-8192", api_key=groq_api)
13
+
14
+ # Create the CSV agent
15
+ agent = create_csv_agent(llm, csv_file_path, verbose=True, allow_dangerous_code=True, handle_parsing_errors=True)
16
+
17
+ # Function to query data
18
+ def query_data(query):
19
+ response = agent.invoke(query)
20
+ return response
21
+
22
+ # Function for Gradio interface
23
+ def get_recommendations(user_query):
24
+ additional_query = '''If you can't find the exact response from the dataframe, you can give the responses similar to the query.
25
+ If you recommend some places, give their descriptions too in a paragraph.
26
+ While giving descriptions, give from the reviews of that place in more than 30 words.
27
+ If there are 'hotels' in the query, recommend hotels only not the restaurants and adventures. And same for other place types.
28
+ Give their revel ratings too.
29
+ Don't try give the descriptions that are not provided in the dataframe.
30
+ Try to minimize giving the same descriptions for more than one places. '''
31
+
32
+ full_query = f"{user_query} {additional_query}"
33
+ response = query_data(full_query)
34
+ return response['output']
35
+
36
+ # Create Gradio interface
37
+ iface = gr.Interface(
38
+ fn=get_recommendations,
39
+ inputs=gr.Textbox(label="Ask your query about hotels:", placeholder="Type your query here..."),
40
+ outputs=gr.Textbox(label="Response will appear here."),
41
+ title="Hotel and Restaurant Recommendation System",
42
+ description="Ask for recommendations based on the data in the CSV file."
43
+ )
44
+
45
+ # Launch the Gradio app
46
+ iface.launch(share=True)