File size: 1,781 Bytes
55798e5
 
 
 
5baa00f
55798e5
d5b1b2a
55798e5
 
 
7b12a39
55798e5
 
 
 
7b12a39
1a46178
55798e5
7b12a39
 
55798e5
 
 
42425e7
55798e5
 
7b12a39
 
 
 
 
55798e5
 
 
 
 
 
 
 
58fe3eb
1a46178
 
 
 
d5b1b2a
7b12a39
 
 
 
 
 
55798e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
from langchain.prompts import PromptTemplate
from langchain_google_genai import ChatGoogleGenerativeAI
import os, spaces
import pandas as pd


os.environ['GOOGLE_API_KEY'] = os.getenv('geminiapi')

# Function for LLM response
def llm_response(columns, df_text, user_prompt):
    # define llm
    llm = ChatGoogleGenerativeAI(model="gemini-pro")
    # define prompt template
    ptemplate = ''' 
    You are an Expert text analyser to find the insights.we have csv file with following columns: {columns} and For the csv content: {df_text},
    find the insights based on given user question: {user_prompt}
    '''
    prompt = PromptTemplate(template=ptemplate,input_variables=['columns','df_text','user_prompt'])
    final_prompt = prompt.format(df_text=df_text, user_prompt=user_prompt, columns=columns)
    # invoke llm to get result
    result = llm.invoke(final_prompt)
    # print result on screen
    st.subheader("Result:")
    st.write(result.content)

def get_user_input():
    user_prompt = st.text_input("Enter User question based on dataframe")
    return user_prompt

    
# define page config
st.set_page_config(
    page_title="Blog Generation",
    page_icon="🧊",
    layout="centered",
    initial_sidebar_state="collapsed",
)

st.header("File Insights🧊")
uploaded_file = st.file_uploader("Upload csv file")
if uploaded_file is not None:
    df = pd.read_csv(uploaded_file, encoding = "ISO-8859-1")
    st.write(df)

    user_prompt = get_user_input()
    # Convert the DataFrame to a text-based context for the model
    df_text = df.to_string(index=False)  # Converts DataFrame to a string for context
    
    # Chat with Google Gemini AI using the DataFrame as context
    llm_response(','.join(df.columns), df_text, user_prompt)