Create Technical_to_Non_Technical_Explainer.py
Browse files
pages/Technical_to_Non_Technical_Explainer.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from llama_index.core import Settings
|
4 |
+
from llama_index.core import VectorStoreIndex, Document
|
5 |
+
from llama_index.embeddings.gemini import GeminiEmbedding
|
6 |
+
from llama_index.llms.gemini import Gemini
|
7 |
+
from llama_index.embeddings.fastembed import FastEmbedEmbedding
|
8 |
+
import google.generativeai as genai
|
9 |
+
import streamlit_analytics2 as streamlit_analytics
|
10 |
+
|
11 |
+
# Set up Google API key (make sure to set this in your environment variables)
|
12 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
13 |
+
|
14 |
+
# Configure Google Gemini
|
15 |
+
Settings.embed_model = GeminiEmbedding(api_key=GOOGLE_API_KEY, model_name="models/embedding-001")
|
16 |
+
Settings.embed_model = FastEmbedEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
17 |
+
Settings.llm = Gemini(api_key=GOOGLE_API_KEY, temperature=0.1, model_name="models/gemini-pro")
|
18 |
+
llm = Gemini(api_key=GOOGLE_API_KEY, temperature=0.1, model_name="models/gemini-pro")
|
19 |
+
|
20 |
+
def generate_explanation(technical_input, audience_level):
|
21 |
+
# Create a document from the technical input
|
22 |
+
document = Document(text=technical_input)
|
23 |
+
|
24 |
+
# Create an index from the document
|
25 |
+
index = VectorStoreIndex.from_documents([document])
|
26 |
+
|
27 |
+
# Create a query engine
|
28 |
+
query_engine = index.as_query_engine()
|
29 |
+
|
30 |
+
# Generate the explanation
|
31 |
+
response = query_engine.query(f"""
|
32 |
+
You are an expert at explaining complex technical concepts to non-technical audiences.
|
33 |
+
Your task is to explain the following technical input in a way that a {audience_level} can understand:
|
34 |
+
|
35 |
+
{technical_input}
|
36 |
+
|
37 |
+
Guidelines:
|
38 |
+
1. Use simple, everyday language and avoid jargon.
|
39 |
+
2. Use analogies or real-world examples to illustrate complex concepts.
|
40 |
+
3. Break down the explanation into easy-to-understand steps or points.
|
41 |
+
4. If you need to use any technical terms, provide clear definitions.
|
42 |
+
5. Focus on the 'why' and 'how' to help the audience grasp the concepts.
|
43 |
+
6. Tailor your explanation to the specified audience level.
|
44 |
+
|
45 |
+
Please provide a clear, concise, and engaging explanation.
|
46 |
+
""")
|
47 |
+
|
48 |
+
return response.response
|
49 |
+
|
50 |
+
def main():
|
51 |
+
st.title("Technical to Non-Technical Explainer")
|
52 |
+
st.write("Enter your technical points or concepts, and our AI will explain them in non-technical terms!")
|
53 |
+
|
54 |
+
with streamlit_analytics.track():
|
55 |
+
# Technical input
|
56 |
+
technical_input = st.text_area("Enter your technical points or concepts", height=150)
|
57 |
+
|
58 |
+
# Audience level selection
|
59 |
+
audience_level = st.selectbox(
|
60 |
+
"Select the knowledge level of your target audience",
|
61 |
+
("Beginner", "Intermediate", "Advanced non-technical")
|
62 |
+
)
|
63 |
+
|
64 |
+
if st.button("Generate Explanation"):
|
65 |
+
if technical_input:
|
66 |
+
st.write("Generating non-technical explanation...")
|
67 |
+
|
68 |
+
explanation = generate_explanation(technical_input, audience_level)
|
69 |
+
|
70 |
+
st.write("## Non-Technical Explanation")
|
71 |
+
st.write(explanation)
|
72 |
+
else:
|
73 |
+
st.warning("Please enter some technical points or concepts to explain.")
|
74 |
+
|
75 |
+
if __name__ == "__main__":
|
76 |
+
main()
|