ysrakeshgupta commited on
Commit
d5b1b2a
·
verified ·
1 Parent(s): 01ae778

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -7
app.py CHANGED
@@ -4,6 +4,12 @@ from langchain_google_genai import ChatGoogleGenerativeAI
4
  import os, spaces
5
  import pandas as pd
6
 
 
 
 
 
 
 
7
  os.environ['GOOGLE_API_KEY'] = os.getenv('geminiapi')
8
 
9
  # Function for LLM response
@@ -32,13 +38,55 @@ st.set_page_config(
32
  )
33
 
34
  st.header("File Insights🧊")
35
- uploaded_file = st.file_uploader("Upload csv file")
36
- if uploaded_file is not None:
37
- df = pd.read_csv(uploaded_file, encoding = "ISO-8859-1")
38
- st.write(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
 
 
40
 
41
- # submit_btn = st.button("Submit")
 
42
 
43
- # if submit_btn:
44
- # llm_response(user_text, number_of_words) # function call for printing results
 
4
  import os, spaces
5
  import pandas as pd
6
 
7
+ import pandas as pd
8
+ from google.cloud import aiplatform
9
+ from google.cloud.aiplatform.gapic import PredictionServiceClient
10
+ from google.cloud.aiplatform.gapic import ChatMessage
11
+
12
+
13
  os.environ['GOOGLE_API_KEY'] = os.getenv('geminiapi')
14
 
15
  # Function for LLM response
 
38
  )
39
 
40
  st.header("File Insights🧊")
41
+ # uploaded_file = st.file_uploader("Upload csv file")
42
+ # if uploaded_file is not None:
43
+ # df = pd.read_csv(uploaded_file, encoding = "ISO-8859-1")
44
+ # st.write(df)
45
+
46
+ # Initialize the AI platform client
47
+ aiplatform.init(project="your-gcp-project-id", location="us-central1")
48
+
49
+ # Example pandas DataFrame
50
+ data = {
51
+ "Name": ["Alice", "Bob", "Charlie", "David"],
52
+ "Age": [25, 30, 35, 40],
53
+ "City": ["New York", "Los Angeles", "Chicago", "Houston"]
54
+ }
55
+ df = pd.DataFrame(data)
56
+
57
+ # Define a function to interact with Google Gemini
58
+ def chat_with_gemini(prompt: str, context: str = ""):
59
+ # Initialize the AI model and set it up for chat-like interactions
60
+ model = aiplatform.gapic.PredictionServiceClient()
61
+
62
+ # Construct the message to send to Gemini
63
+ prompt_message = ChatMessage(
64
+ role="user",
65
+ content=prompt
66
+ )
67
+
68
+ context_message = ChatMessage(
69
+ role="system",
70
+ content=context
71
+ )
72
+
73
+ # Send the request to Google Gemini and get the response
74
+ response = model.chat_messages(
75
+ model="projects/your-gcp-project-id/locations/us-central1/models/your-model-id", # Model ID for Google Gemini
76
+ messages=[context_message, prompt_message]
77
+ )
78
+
79
+ # Return the response content
80
+ return response[0].content
81
+
82
+ # Convert the DataFrame to a text-based context for the model
83
+ df_text = df.to_string(index=False) # Converts DataFrame to a string for context
84
 
85
+ # Example interaction: Ask the AI model a question about the DataFrame
86
+ prompt = "What is the average age in the dataset?"
87
 
88
+ # Chat with Google Gemini AI using the DataFrame as context
89
+ response = chat_with_gemini(prompt, context=df_text)
90
 
91
+ # Print the AI's response
92
+ print(response)