parthib07 commited on
Commit
2098354
·
verified ·
1 Parent(s): c4f4fe0

Upload 6 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Research/video.mp4 filter=lfs diff=lfs merge=lfs -text
Research/checking.ipynb ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from dotenv import load_dotenv\n",
10
+ "load_dotenv()\n",
11
+ "import os \n",
12
+ "\n",
13
+ "api_key = os.environ.get('GOOGLE_API_KEY')"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "import google.generativeai as genai\n",
23
+ "genai.configure(api_key = api_key)"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": 4,
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "\n",
33
+ "file = genai.upload_file(\"video.mp4\")"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 5,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "from llama_index.llms.gemini import Gemini\n",
43
+ "llm = Gemini(model_name = \"models/gemini-1.5-pro\")\n",
44
+ "response = llm.complete([\"tell me the content of this video\",file])"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 7,
50
+ "metadata": {},
51
+ "outputs": [
52
+ {
53
+ "data": {
54
+ "text/plain": [
55
+ "'This video is a tutorial on linear regression. The narrator explains that linear regression is a statistical technique for modeling the relationship between an output variable and one or more input variables. The narrator explains that this is done by fitting a line through data points. The narrator explains the linear function y = mx + b, where y is the output variable, x is the input variable, m is the slope of the line, and b is the intercept of the line. The narrator explains that the coefficients m and b are what are solved for in linear regression. The narrator explains that the differences between the points and the line are called residuals. The narrator explains that the sum of the squared errors is the loss function. The narrator explains that the coefficients can be solved with a variety of techniques, including matrix decomposition and gradient descent. The narrator explains that to validate a linear regression, a third of the data is put into a test data set, and the remaining two-thirds become the training data set. The training data set is used to fit the regression line, and the test data set is used to validate the regression line. The narrator explains that metrics used to evaluate the linear regression vary from the r-squared, standard error of the estimate, prediction intervals, and statistical significance. The narrator recommends two books, “Essential Math for Data Science” and “Getting Started with SQL.” The narrator also teaches classes on the O’Reilly platform, including machine learning from scratch, probability, and SQL.'"
56
+ ]
57
+ },
58
+ "execution_count": 7,
59
+ "metadata": {},
60
+ "output_type": "execute_result"
61
+ }
62
+ ],
63
+ "source": [
64
+ "response.text"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "execution_count": null,
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": []
73
+ }
74
+ ],
75
+ "metadata": {
76
+ "kernelspec": {
77
+ "display_name": "Python 3",
78
+ "language": "python",
79
+ "name": "python3"
80
+ },
81
+ "language_info": {
82
+ "codemirror_mode": {
83
+ "name": "ipython",
84
+ "version": 3
85
+ },
86
+ "file_extension": ".py",
87
+ "mimetype": "text/x-python",
88
+ "name": "python",
89
+ "nbconvert_exporter": "python",
90
+ "pygments_lexer": "ipython3",
91
+ "version": "3.10.0"
92
+ }
93
+ },
94
+ "nbformat": 4,
95
+ "nbformat_minor": 2
96
+ }
Research/notebook1.ipynb ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 23,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from dotenv import load_dotenv\n",
10
+ "load_dotenv()\n",
11
+ "import os \n",
12
+ "\n",
13
+ "api_key = os.environ.get('GOOGLE_API_KEY')"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 24,
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "import google.generativeai as genai\n",
23
+ "genai.configure(api_key = api_key)"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": 25,
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "Model = genai.GenerativeModel(model_name=\"models/gemini-1.5-pro\")\n",
33
+ "\n",
34
+ "file = genai.upload_file(\"video.mp4\")"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 27,
40
+ "metadata": {},
41
+ "outputs": [],
42
+ "source": [
43
+ "response = Model.generate_content([\"Tell me the summury of this video\",file])"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 28,
49
+ "metadata": {},
50
+ "outputs": [
51
+ {
52
+ "data": {
53
+ "text/plain": [
54
+ "'This video explains linear regression, a statistical technique used to model the relationship between an output variable and one or more input variables. In simpler terms, this means fitting a line through data points and making predictions using that line. The formula for this is y equals mx + b, where y is the output variable, also called the dependent variable. The x is the input variable, called the independent variable. The m and b variables are the coefficients that are solved for in linear regression. The m variable controls the slope of the line. The b variable controls the intercept of the line. These are also referred to as beta1 and beta0. This equation can also have multiple input variables x1, x2, and x3.\\n\\nThe video also explains how to find the best fit for the regression line using residuals or the differences between the data points and the line. Squaring the residuals, then totaling these squares for a given line will get the sum of squared error (SSE). The beta coefficients that minimize the SSE are the most appropriate for the data.\\n\\nTo validate the regression, machine learning practitioners often divide the data into a training set and a test set. They use the training set to fit the regression line, then use the test set to validate the line. They use the r-squared, standard error, prediction intervals, and statistical significance metrics to evaluate the regression.'"
55
+ ]
56
+ },
57
+ "execution_count": 28,
58
+ "metadata": {},
59
+ "output_type": "execute_result"
60
+ }
61
+ ],
62
+ "source": [
63
+ "response.text"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 29,
69
+ "metadata": {},
70
+ "outputs": [
71
+ {
72
+ "data": {
73
+ "text/markdown": [
74
+ "This video explains linear regression, a statistical technique used to model the relationship between an output variable and one or more input variables. In simpler terms, this means fitting a line through data points and making predictions using that line. The formula for this is y equals mx + b, where y is the output variable, also called the dependent variable. The x is the input variable, called the independent variable. The m and b variables are the coefficients that are solved for in linear regression. The m variable controls the slope of the line. The b variable controls the intercept of the line. These are also referred to as beta1 and beta0. This equation can also have multiple input variables x1, x2, and x3.\n",
75
+ "\n",
76
+ "The video also explains how to find the best fit for the regression line using residuals or the differences between the data points and the line. Squaring the residuals, then totaling these squares for a given line will get the sum of squared error (SSE). The beta coefficients that minimize the SSE are the most appropriate for the data.\n",
77
+ "\n",
78
+ "To validate the regression, machine learning practitioners often divide the data into a training set and a test set. They use the training set to fit the regression line, then use the test set to validate the line. They use the r-squared, standard error, prediction intervals, and statistical significance metrics to evaluate the regression."
79
+ ],
80
+ "text/plain": [
81
+ "<IPython.core.display.Markdown object>"
82
+ ]
83
+ },
84
+ "metadata": {},
85
+ "output_type": "display_data"
86
+ }
87
+ ],
88
+ "source": [
89
+ "from IPython.display import Markdown\n",
90
+ "display(Markdown(response.text))"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 30,
96
+ "metadata": {},
97
+ "outputs": [],
98
+ "source": [
99
+ "response = Model.generate_content([\"what is the equations provided in the video\",file])"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": 31,
105
+ "metadata": {},
106
+ "outputs": [
107
+ {
108
+ "data": {
109
+ "text/plain": [
110
+ "'The narrator in this video describes the basic process of using linear regression, a type of statistical modeling that assumes a linear relationship between variables. In the equation, the output or dependent variable y can be expressed as a function of an input or independent variable, such as x, or as several input variables, x1, x2, x3, etc. He shows the two main ways these equations are generally expressed:\\n\\ny=mx+b\\nf(x) = mx + b\\ny = β1x + β0\\ny = β2x2 + β1x1 + β0\\ny = β3x3 + β2x2 + β1x1 + β0\\ny = β4x4 + β3x3 + β2x2 + β1x1 + β0\\ny = β5x5 + β4x4 + β3x3 + β2x2 + β1x1 + β0\\n\\n\\n'"
111
+ ]
112
+ },
113
+ "execution_count": 31,
114
+ "metadata": {},
115
+ "output_type": "execute_result"
116
+ }
117
+ ],
118
+ "source": [
119
+ "response.text"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 32,
125
+ "metadata": {},
126
+ "outputs": [
127
+ {
128
+ "data": {
129
+ "text/markdown": [
130
+ "The narrator in this video describes the basic process of using linear regression, a type of statistical modeling that assumes a linear relationship between variables. In the equation, the output or dependent variable y can be expressed as a function of an input or independent variable, such as x, or as several input variables, x1, x2, x3, etc. He shows the two main ways these equations are generally expressed:\n",
131
+ "\n",
132
+ "y=mx+b\n",
133
+ "f(x) = mx + b\n",
134
+ "y = β1x + β0\n",
135
+ "y = β2x2 + β1x1 + β0\n",
136
+ "y = β3x3 + β2x2 + β1x1 + β0\n",
137
+ "y = β4x4 + β3x3 + β2x2 + β1x1 + β0\n",
138
+ "y = β5x5 + β4x4 + β3x3 + β2x2 + β1x1 + β0\n",
139
+ "\n",
140
+ "\n"
141
+ ],
142
+ "text/plain": [
143
+ "<IPython.core.display.Markdown object>"
144
+ ]
145
+ },
146
+ "metadata": {},
147
+ "output_type": "display_data"
148
+ }
149
+ ],
150
+ "source": [
151
+ "display(Markdown(response.text))"
152
+ ]
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "execution_count": null,
157
+ "metadata": {},
158
+ "outputs": [],
159
+ "source": []
160
+ }
161
+ ],
162
+ "metadata": {
163
+ "kernelspec": {
164
+ "display_name": "Python 3",
165
+ "language": "python",
166
+ "name": "python3"
167
+ },
168
+ "language_info": {
169
+ "codemirror_mode": {
170
+ "name": "ipython",
171
+ "version": 3
172
+ },
173
+ "file_extension": ".py",
174
+ "mimetype": "text/x-python",
175
+ "name": "python",
176
+ "nbconvert_exporter": "python",
177
+ "pygments_lexer": "ipython3",
178
+ "version": "3.10.0"
179
+ }
180
+ },
181
+ "nbformat": 4,
182
+ "nbformat_minor": 2
183
+ }
Research/video.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da41d641e9f6eba6ccffe1ffe52a428fa02118df369716d537e11484904c877e
3
+ size 6121500
backend.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import google.generativeai as genai
2
+ from llama_index.llms.gemini import Gemini
3
+ from llama_index.embeddings.gemini import GeminiEmbedding
4
+ import os
5
+ import tempfile
6
+ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
7
+ from llama_index.core import Settings
8
+ import time
9
+ from google.api_core.exceptions import GoogleAPIError
10
+ import streamlit as st
11
+
12
+ genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
13
+
14
+ llm = Gemini(model_name="models/gemini-1.5-pro")
15
+ embeddings = GeminiEmbedding(model_name="models/embedding-001")
16
+
17
+ def normal_response(query):
18
+ prompt = """You are a helpful Bot named VisionLang Build by Parthib Karak.
19
+ Given a question, generate answer based on the Question.
20
+ Question: {question}
21
+ """
22
+ try:
23
+ response = llm.complete(prompt + query)
24
+ return response.text
25
+ except GoogleAPIError as e:
26
+ return f"Error generating response: {str(e)}"
27
+
28
+ def uploaded_file_to_response(file, query):
29
+ file_extension = os.path.splitext(file.name)[-1].lower()
30
+ try:
31
+ if file_extension in [".pdf", ".docx", ".txt", ".py", ".js", ".java", ".cpp"]:
32
+ temp_dir = tempfile.mkdtemp()
33
+ temp_file_path = os.path.join(temp_dir, file.name)
34
+ with open(temp_file_path, "wb") as f:
35
+ f.write(file.read())
36
+
37
+ document = SimpleDirectoryReader(temp_dir)
38
+ data = document.load_data()
39
+ Settings.llm = llm
40
+ Settings.embed_model = embeddings
41
+ index = VectorStoreIndex.from_documents(data, settings=Settings)
42
+ query_engine = index.as_query_engine()
43
+ response = query_engine.query(query)
44
+ return response
45
+ elif file_extension in [".mp4", ".avi", ".mov",".mkv"]:
46
+ temp_dir = tempfile.mkdtemp()
47
+ temp_file_path = os.path.join(temp_dir, file.name)
48
+ with open(temp_file_path, "wb") as f:
49
+ f.write(file.read())
50
+
51
+ uploaded_file = genai.upload_file(temp_file_path, mime_type="video/mp4")
52
+ st.success("video uploaded successfully")
53
+ time.sleep(2)
54
+ response = llm.complete([query, uploaded_file])
55
+ return response.text
56
+ elif file_extension in [".png", ".jpg", ".jpeg"]:
57
+ uploaded_file = genai.upload_file(file, mime_type="image/jpeg")
58
+ time.sleep(2)
59
+ response = llm.complete([query, uploaded_file])
60
+ return response.text
61
+ else:
62
+ uploaded_file = genai.upload_file(file, mime_type="application/octet-stream")
63
+ time.sleep(2)
64
+ response = llm.complete([query, uploaded_file])
65
+ return response.text
66
+ except GoogleAPIError as e:
67
+ return f"Error processing file: {str(e)}"
68
+
main.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from backend import uploaded_file_to_response, normal_response
3
+ from llama_index.llms.gemini import Gemini
4
+ from llama_index.embeddings.gemini import GeminiEmbedding
5
+ import google.generativeai as genai
6
+ import os
7
+ from dotenv import load_dotenv
8
+ load_dotenv()
9
+
10
+ genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
11
+
12
+ llm = Gemini(model_name="models/gemini-1.5-pro")
13
+ embeddings = GeminiEmbedding(model_name="models/embedding-001")
14
+
15
+ if "chat_history" not in st.session_state:
16
+ st.session_state.chat_history = []
17
+
18
+ st.markdown("""
19
+ <style>
20
+ .stApp { background-color: #ffffff; color: black; font-family: 'Arial', sans-serif; }
21
+ .title { font-size: 36px; font-weight: bold; text-align: center; animation: fadeIn 2s ease-in-out; }
22
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
23
+ .chat-container { max-height: 500px; overflow-y: auto; display: flex; flex-direction: column-reverse; padding: 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.05); margin-top: 10px; }
24
+ .user-message { background: #0078ff; color: white; padding: 10px; border-radius: 10px; margin-bottom: 5px; text-align: left; }
25
+ .ai-message { background: #f1f1f1; color: black; padding: 10px; border-radius: 10px; margin-bottom: 5px; text-align: left; }
26
+ .btn-style { background: linear-gradient(45deg, #ff007f, #ff0055); color: white; padding: 8px 16px; border-radius: 6px; font-size: 14px; margin-top: 10px; transition: 0.3s ease-in-out; border: none; cursor: pointer; }
27
+ .btn-style:hover { background: linear-gradient(45deg, #ff0055, #d4005a); }
28
+ </style>
29
+ """, unsafe_allow_html=True)
30
+
31
+ st.markdown("<h1 class='title'>🧠 AI Code Companion</h1>", unsafe_allow_html=True)
32
+ st.caption("🚀 Upload files & chat with AI")
33
+
34
+ uploaded_file = st.file_uploader("Upload a File (Image, Document, Code, Video, or Audio)", type=["png", "jpg", "jpeg", "pdf", "docx", "txt", "py", "js", "java", "cpp", "mp4"], key="file_uploader")
35
+
36
+ user_input = st.text_input("Type your message here...", key="chat_input", help="Chat with AI", label_visibility="collapsed")
37
+
38
+ if st.button("Generate Response", key="generate_button", help="Click to get AI response", use_container_width=False):
39
+ if user_input:
40
+ with st.spinner("Processing..."):
41
+ response = normal_response(user_input)
42
+ if uploaded_file:
43
+ response = uploaded_file_to_response(uploaded_file, user_input)
44
+ st.session_state.chat_history.insert(0, (user_input, response))
45
+
46
+ if st.session_state.chat_history:
47
+ chat_container = st.container()
48
+ with chat_container:
49
+ st.markdown("### Chat History")
50
+ for user_msg, ai_response in st.session_state.chat_history:
51
+ st.markdown(f"<div class='user-message'><b>You:</b> {user_msg}</div>", unsafe_allow_html=True)
52
+ st.markdown(f"<div class='ai-message'><b>AI:</b> {ai_response}</div>", unsafe_allow_html=True)
53
+ st.markdown("<br>", unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ google-generativeai
2
+ llama-index-llms-gemini
3
+ llama-index-embeddings-gemini
4
+ python-dotenv