import pandas as pd from langchain_groq import ChatGroq from langchain_experimental.agents.agent_toolkits import create_csv_agent import gradio as gr # Reading a CSV file csv_file_path = 'final_dataset.csv' df_csv = pd.read_csv(csv_file_path) # Initialize the Groq API and the LLM groq_api = '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' llm = ChatGroq(temperature=0, model="llama3-70b-8192", api_key=groq_api) # Create the CSV agent agent = create_csv_agent(llm, csv_file_path, verbose=True, allow_dangerous_code=True, handle_parsing_errors=True) # Function to query data def query_data(query): response = agent.invoke(query) return response # Function for Gradio interface def get_recommendations(user_query): additional_query = '''If you can't find the exact response from the dataframe, you can give the responses similar to the query. If you recommend some places, give their descriptions too in a paragraph. While giving descriptions, give from the reviews of that place in more than 30 words. If there are 'hotels' in the query, recommend hotels only not the restaurants and adventures. And same for other place types. Give their revel ratings too. Don't try give the descriptions that are not provided in the dataframe. Try to minimize giving the same descriptions for more than one places. ''' full_query = f"{user_query} {additional_query}" response = query_data(full_query) return response['output'] # Create Gradio interface iface = gr.Interface( fn=get_recommendations, inputs=gr.Textbox(label="Ask your query about hotels:", placeholder="Type your query here..."), outputs=gr.Textbox(label="Response will appear here."), title="Hotel and Restaurant Recommendation System", description="Ask for recommendations based on the data in the CSV file." ) # Launch the Gradio app iface.launch(share=True)