|
import os |
|
import streamlit as st |
|
from llama_index.core import Settings |
|
from llama_index.core import VectorStoreIndex, Document |
|
from llama_index.embeddings.gemini import GeminiEmbedding |
|
from llama_index.llms.gemini import Gemini |
|
from llama_index.embeddings.fastembed import FastEmbedEmbedding |
|
import google.generativeai as genai |
|
import streamlit_analytics2 as streamlit_analytics |
|
|
|
|
|
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") |
|
|
|
|
|
Settings.embed_model = GeminiEmbedding(api_key=GOOGLE_API_KEY, model_name="models/embedding-001") |
|
Settings.embed_model = FastEmbedEmbedding(model_name="BAAI/bge-small-en-v1.5") |
|
Settings.llm = Gemini(api_key=GOOGLE_API_KEY, temperature=0.1, model_name="models/gemini-pro") |
|
llm = Gemini(api_key=GOOGLE_API_KEY, temperature=0.1, model_name="models/gemini-pro") |
|
|
|
def generate_explanation(technical_input, audience_level): |
|
|
|
document = Document(text=technical_input) |
|
|
|
|
|
index = VectorStoreIndex.from_documents([document]) |
|
|
|
|
|
query_engine = index.as_query_engine() |
|
|
|
|
|
response = query_engine.query(f""" |
|
You are an expert at explaining complex technical concepts to non-technical audiences. |
|
Your task is to explain the following technical input in a way that a {audience_level} can understand: |
|
|
|
{technical_input} |
|
|
|
Guidelines: |
|
1. Use simple, everyday language and avoid jargon. |
|
2. Use analogies or real-world examples to illustrate complex concepts. |
|
3. Break down the explanation into easy-to-understand steps or points. |
|
4. If you need to use any technical terms, provide clear definitions. |
|
5. Focus on the 'why' and 'how' to help the audience grasp the concepts. |
|
6. Tailor your explanation to the specified audience level. |
|
|
|
Please provide a clear, concise, and engaging explanation. |
|
""") |
|
|
|
return response.response |
|
|
|
def main(): |
|
st.title("Technical to Non-Technical Explainer") |
|
st.write("Enter your technical points or concepts, and our AI will explain them in non-technical terms!") |
|
|
|
with streamlit_analytics.track(): |
|
|
|
technical_input = st.text_area("Enter your technical points or concepts", height=150) |
|
|
|
|
|
audience_level = st.selectbox( |
|
"Select the knowledge level of your target audience", |
|
("Beginner", "Intermediate", "Advanced non-technical") |
|
) |
|
|
|
if st.button("Generate Explanation"): |
|
if technical_input: |
|
st.write("Generating non-technical explanation...") |
|
|
|
explanation = generate_explanation(technical_input, audience_level) |
|
|
|
st.write("## Non-Technical Explanation") |
|
st.write(explanation) |
|
else: |
|
st.warning("Please enter some technical points or concepts to explain.") |
|
|
|
if __name__ == "__main__": |
|
main() |