Upload 5 files
Browse files- .gitattributes +1 -0
- app.py +60 -0
- chunks.pkl +3 -0
- requirements.txt +0 -0
- solar panel technology.docx +0 -0
- solar_vectors.index +3 -0
.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 |
+
solar_vectors.index filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import faiss
|
| 2 |
+
from sentence_transformers import SentenceTransformer
|
| 3 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
+
from langchain_groq import ChatGroq
|
| 5 |
+
import os
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import numpy as np
|
| 8 |
+
import pickle
|
| 9 |
+
|
| 10 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 11 |
+
index = faiss.read_index("solar_vectors.index")
|
| 12 |
+
with open("chunks.pkl", "rb") as f:
|
| 13 |
+
chunks= pickle.load(f)
|
| 14 |
+
|
| 15 |
+
os.environ["GROQ_API_KEY"]= "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"
|
| 16 |
+
llm = ChatGroq(model="mixtral-8x7b-32768",temperature=0)
|
| 17 |
+
|
| 18 |
+
def retrieve_relevant_text(query, top_k=1):
|
| 19 |
+
query_embedding = model.encode([query])
|
| 20 |
+
distances, indices = index.search(np.array(query_embedding), top_k)
|
| 21 |
+
return [chunks[i] for i in indices[0]]
|
| 22 |
+
|
| 23 |
+
def generate_response(user_query):
|
| 24 |
+
retrieved_text = retrieve_relevant_text(user_query, top_k=4)
|
| 25 |
+
system_message = "You are an intelligent assistant that provides accurate, helpful information about solar energy based on the information provided(if not, answer according to your knowledge)."
|
| 26 |
+
prompt_template = ChatPromptTemplate.from_messages([
|
| 27 |
+
("system", system_message),
|
| 28 |
+
("human", f"Use the following information to answer: {retrieved_text} \n\nUser Query: {user_query}")
|
| 29 |
+
])
|
| 30 |
+
|
| 31 |
+
chain = prompt_template | llm
|
| 32 |
+
response = chain.invoke({"text": user_query})
|
| 33 |
+
return response.content
|
| 34 |
+
|
| 35 |
+
def gradio_chatbot(user_input):
|
| 36 |
+
response = generate_response(user_input)
|
| 37 |
+
return response
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
gr.Markdown("# ๐ SolarAI ๐")
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
user_input = gr.Textbox(
|
| 46 |
+
placeholder="Ask me anything about solar energy...",
|
| 47 |
+
lines=2,
|
| 48 |
+
interactive=True
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
output_box = gr.Textbox(
|
| 53 |
+
lines=12,
|
| 54 |
+
interactive=True,
|
| 55 |
+
label="Chatbot Response"
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
submit_btn = gr.Button("Ask")
|
| 59 |
+
submit_btn.click(fn=gradio_chatbot, inputs=user_input, outputs=output_box)
|
| 60 |
+
demo.launch()
|
chunks.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9475dd916aac98cd0830ace75ff9865926aafed8494f40dacbb4be416dcd9faa
|
| 3 |
+
size 20511
|
requirements.txt
ADDED
|
Binary file (2.92 kB). View file
|
|
|
solar panel technology.docx
ADDED
|
Binary file (27.8 kB). View file
|
|
|
solar_vectors.index
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:960470d1a6a6e494effbfb4e8138e40dcabfd24b06484aa25dee7ae620cc4fbb
|
| 3 |
+
size 113709
|