repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import csv |
| #2 | import queue |
| #3 | import threading |
| #4 | from io import StringIO |
| #5 | |
| #6 | import requests |
| #7 | import streamlit as st |
| #8 | |
| #9 | from embedchain import App |
| #10 | from embedchain.config import BaseLlmConfig |
| #11 | from embedchain.helpers.callbacks import StreamingStdOutCallbackHandlerYield, generate |
| #12 | |
| #13 | |
| #14 | @st.cache_resource |
| #15 | def sadhguru_ai(): |
| #16 | app = App() |
| #17 | return app |
| #18 | |
| #19 | |
| #20 | # Function to read the CSV file row by row |
| #21 | def read_csv_row_by_row(file_path): |
| #22 | with open(file_path, mode="r", newline="", encoding="utf-8") as file: |
| #23 | csv_reader = csv.DictReader(file) |
| #24 | for row in csv_reader: |
| #25 | yield row |
| #26 | |
| #27 | |
| #28 | @st.cache_resource |
| #29 | def add_data_to_app(): |
| #30 | app = sadhguru_ai() |
| #31 | url = "https://gist.githubusercontent.com/deshraj/50b0597157e04829bbbb7bc418be6ccb/raw/95b0f1547028c39691f5c7db04d362baa597f3f4/data.csv" # noqa:E501 |
| #32 | response = requests.get(url) |
| #33 | csv_file = StringIO(response.text) |
| #34 | for row in csv.reader(csv_file): |
| #35 | if row and row[0] != "url": |
| #36 | app.add(row[0], data_type="web_page") |
| #37 | |
| #38 | |
| #39 | app = sadhguru_ai() |
| #40 | add_data_to_app() |
| #41 | |
| #42 | assistant_avatar_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Sadhguru-Jaggi-Vasudev.jpg/640px-Sadhguru-Jaggi-Vasudev.jpg" # noqa: E501 |
| #43 | |
| #44 | |
| #45 | st.title("🙏 Sadhguru AI") |
| #46 | |
| #47 | styled_caption = '<p style="font-size: 17px; color: #aaa;">🚀 An <a href="https://github.com/embedchain/embedchain">Embedchain</a> app powered with Sadhguru\'s wisdom!</p>' # noqa: E501 |
| #48 | st.markdown(styled_caption, unsafe_allow_html=True) # noqa: E501 |
| #49 | |
| #50 | if "messages" not in st.session_state: |
| #51 | st.session_state.messages = [ |
| #52 | { |
| #53 | "role": "assistant", |
| #54 | "content": """ |
| #55 | Hi, I'm Sadhguru AI! I'm a mystic, yogi, visionary, and spiritual master. I'm here to answer your questions about life, the universe, and everything. |
| #56 | """, # noqa: E501 |
| #57 | } |
| #58 | ] |
| #59 | |
| #60 | for message in st.session_state.messages: |
| #61 | role = message["role"] |
| #62 | with st.chat_message(role, avatar=assistant_avatar_url if role == "assistant" else None): |
| #63 | st.markdown(message["content"]) |
| #64 | |
| #65 | if prompt := st.chat_input("Ask me anything!"): |
| #66 | with st.chat_message("user"): |
| #67 | st.markdown(prompt) |
| #68 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #69 | |
| #70 | with st.chat_message("assistant", avatar=assistant_avatar_url): |
| #71 | msg_placeholder = st.empty() |
| #72 | msg_placeholder.markdown("Thinking...") |
| #73 | full_response = "" |
| #74 | |
| #75 | q = queue.Queue() |
| #76 | |
| #77 | def app_response(result): |
| #78 | config = BaseLlmConfig(stream=True, callbacks=[StreamingStdOutCallbackHandlerYield(q)]) |
| #79 | answer, citations = app.chat(prompt, config=config, citations=True) |
| #80 | result["answer"] = answer |
| #81 | result["citations"] = citations |
| #82 | |
| #83 | results = {} |
| #84 | thread = threading.Thread(target=app_response, args=(results,)) |
| #85 | thread.start() |
| #86 | |
| #87 | for answer_chunk in generate(q): |
| #88 | full_response += answer_chunk |
| #89 | msg_placeholder.markdown(full_response) |
| #90 | |
| #91 | thread.join() |
| #92 | answer, citations = results["answer"], results["citations"] |
| #93 | if citations: |
| #94 | full_response += "\n\n**Sources**:\n" |
| #95 | sources = list(set(map(lambda x: x[1]["url"], citations))) |
| #96 | for i, source in enumerate(sources): |
| #97 | full_response += f"{i+1}. {source}\n" |
| #98 | |
| #99 | msg_placeholder.markdown(full_response) |
| #100 | st.session_state.messages.append({"role": "assistant", "content": full_response}) |
| #101 |