init commit
Browse files- .gitignore +3 -0
- app.py +44 -0
- dummy_data/2025-11-01.md +8 -0
- dummy_data/2025-11-02.md +7 -0
- dummy_data/2025-11-03.md +5 -0
- dummy_data/2025-11-04.md +7 -0
- dummy_data/2025-11-05.md +5 -0
- dummy_data/2025-11-06.md +5 -0
- dummy_data/2025-11-07.md +9 -0
- requirments.txt +4 -0
- src/agent.py +55 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv
|
| 2 |
+
.env
|
| 3 |
+
__pycache__
|
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from src.agent import Agent
|
| 4 |
+
import nest_asyncio
|
| 5 |
+
from llama_index.llms.google_genai import GoogleGenAI
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
|
| 12 |
+
|
| 13 |
+
agent = Agent()
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
|
| 17 |
+
# nest_asyncio.apply()
|
| 18 |
+
|
| 19 |
+
llm = GoogleGenAI(model="gemini-2.5-flash-lite")
|
| 20 |
+
|
| 21 |
+
# temp
|
| 22 |
+
folder_path = "./dummy_data"
|
| 23 |
+
|
| 24 |
+
agent.load_and_index_folder(folder_path, llm)
|
| 25 |
+
|
| 26 |
+
def query_agent(query_text, chat_history):
|
| 27 |
+
response = agent.query_index(query_text)
|
| 28 |
+
return str(response)
|
| 29 |
+
|
| 30 |
+
iface = gr.ChatInterface(
|
| 31 |
+
fn=query_agent,
|
| 32 |
+
chatbot=gr.Chatbot(height="600"),
|
| 33 |
+
textbox=gr.Textbox(placeholder="Ask me a question...", container=False, scale=7),
|
| 34 |
+
title="RAG Agent Chatbot",
|
| 35 |
+
description="Ask questions about your journal entries.",
|
| 36 |
+
examples=["What are my hobbies?", "Who are my friends that I play Rocket League with?"],
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
iface.launch(share=False)
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
main()
|
| 43 |
+
|
| 44 |
+
|
dummy_data/2025-11-01.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
I’m starting this journaling thing again because everyone keeps saying it’s supposed to help with stress. I don’t know if it actually will, but whatever, I’ll try. Today was mostly me staring at my laptop, trying to rewrite my Harvard personal statement. I hate how every time I think I’ve got a solid draft, I read it again and it sounds braggy or fake or like I’m trying way too hard. Maybe I am trying too hard. I don’t know. I just keep thinking: what if none of this is enough? What if I’m just another “used-to-be-gifted” kid who peaked in middle school?
|
| 3 |
+
|
| 4 |
+
After forcing myself to write for an hour, I played guitar for a while. I’m trying to learn this impossible fingerstyle cover from YouTube. It’s weird how I can focus for hours on that but not on something that actually matters for my future. Mom peeked in and asked how essays were going. I said “fine,” because I didn’t want to explain that I deleted half my draft again.
|
| 5 |
+
|
| 6 |
+
Tonight I played Rocket League with Jake and Mason. They kept joking about me “going Ivy and never speaking to the peasants again,” and I laughed, but it made me uncomfortable. I don’t want people thinking I’m only about prestige. But maybe I am? Ugh.
|
| 7 |
+
|
| 8 |
+
I keep thinking about how everyone said I was “full of potential” when I was younger, and I feel like I have to prove it now. Like if I don’t get into a top school, I’ll be letting everyone down. I wish I didn’t care so much, but I do. I honestly do.
|
dummy_data/2025-11-02.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
I met with my English teacher, Mr. Harris, about my Common App essay. He said I need to make it “more personal, less performance.” I pretended to understand what that means, but I kinda don’t. I thought the point was to perform, to show them I’m impressive. Isn’t that how college admissions works? You convince strangers you’re special?
|
| 2 |
+
|
| 3 |
+
I practiced piano for a while after school because my fingers were shaking from stress. I kept messing up on songs I normally play perfectly. Honestly, I wanted to cry, which is embarrassing to think about. I feel like my brain won’t stop buzzing lately.
|
| 4 |
+
|
| 5 |
+
Dad brought up Princeton at dinner. He asked if I had reached out to the recommendation teachers yet. I told him yes. Lie. I haven’t. I know I need to, but something in me freezes every time I try to write the email. What if they say no? Or worse, what if they say yes but secretly roll their eyes because I’m not as impressive as I used to be?
|
| 6 |
+
|
| 7 |
+
I read somewhere that procrastination is fear. If that’s true, then I must be terrified.
|
dummy_data/2025-11-03.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
I actually worked on my essay in the library during lunch. For like… forty minutes. That’s something, right? I still hate it, though. I tried to write about how being labeled “gifted” messed with my head, but it sounded whiny, so I deleted half again. I don’t know how to say something real without sounding dramatic.
|
| 2 |
+
|
| 3 |
+
After school, I played guitar again, and for a few minutes, I forgot about deadlines and expectations and all that. It’s like music is the only place I feel like myself. Which is weird because I don’t even know who “myself” is supposed to be.
|
| 4 |
+
|
| 5 |
+
Why do these schools matter so much? I keep saying it’s because I want to challenge myself, meet smart people, have opportunities, blah blah. But is that really true? Or do I just want the name, the recognition, so people stop worrying that I wasted my potential? I don’t know. I’m not sure I want to think about it.
|
dummy_data/2025-11-04.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
I finally emailed my teachers about recommendations. Hit send. Wanted to throw up. They both responded way nicer than I expected, though. Maybe I’m not as disappointing as I think, or maybe they’re just polite. Whatever, I’ll take it.
|
| 2 |
+
|
| 3 |
+
Played Rocket League again. It’s the only time I don’t script everything I say in my head first. I just react, and it feels… lighter. We lost a ton of matches, but honestly, it didn’t bother me like it usually does. Maybe because losing at a game doesn’t threaten my entire identity.
|
| 4 |
+
|
| 5 |
+
Mom asked if I’ve considered backup schools. I snapped at her. I don’t know why. She wasn’t attacking me. But the idea of a “backup” makes my chest tighten. Like admitting I might fail. I later apologized, but I still feel gross about it.
|
| 6 |
+
|
| 7 |
+
I started wondering something: what if I accomplish all this stuff, get into a big-name school, graduate, and then realize I’ve been chasing the wrong goal? I don’t know if that’s a real fear or just my brain being dramatic.
|
dummy_data/2025-11-05.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Long day. I had a mini breakdown in the bathroom between classes. Nothing big, no one saw, but still. I think I’m burning out before college even starts. Everyone keeps talking about early action deadlines, comparing SAT scores, bragging about internships. I nod and pretend I’m okay, but I feel like I’m shrinking inside.
|
| 2 |
+
|
| 3 |
+
Practiced piano again. I messed up a ton and got mad at myself and slammed the keys. Then I felt stupid. It’s like I don’t know how to be gentle with myself. I don’t even know what that would look like.
|
| 4 |
+
|
| 5 |
+
I keep noticing this pattern: every time I talk to Dad about college, I spiral afterward. Not because he says anything mean, but because I want him to be proud so badly that I freak out. I don’t want to need his approval this much. I wish I didn’t.
|
dummy_data/2025-11-06.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Good news: I edited almost two full pages of the Yale supplement. Bad news: I stayed up until 3 AM playing guitar and scrolling forums about Ivy admissions. People online sound like robots sometimes. “My research at MIT’s nanotech lab…” I mean, good for them, but it makes me feel small.
|
| 2 |
+
|
| 3 |
+
I hung out with my friend Lily after school. We got coffee, and she talked about maybe going to art school in Chicago. She sounded… excited. Like she actually wants something. I realized I rarely talk about what I want, only what I “should” do. That’s kind of sad.
|
| 4 |
+
|
| 5 |
+
Is it bad that sometimes I want a normal life? Not boring, just not… constantly proving something. I used to enjoy learning just because it was interesting. I don’t remember the last time that was true.
|
dummy_data/2025-11-07.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
I turned in my Harvard application today. My hands were shaking when I pressed submit. I thought I would feel relieved, but mostly I feel empty. Like now it’s out of my control, which honestly terrifies me.
|
| 2 |
+
|
| 3 |
+
After school, I played piano for a long time, then switched to guitar, then accidentally took a nap on the floor. I think I’m exhausted from caring so much. I wonder if other people feel like this or if it’s just me being dramatic again.
|
| 4 |
+
|
| 5 |
+
I noticed something today: I always feel more anxious at night, especially after talking about college. During the day, when I’m laughing with people or messing around or playing music, I almost forget the pressure. Maybe that means something. Maybe it doesn’t.
|
| 6 |
+
|
| 7 |
+
I don’t know who I’ll be if I don’t get into these schools. But maybe I should figure that out, because I can’t keep basing my whole identity on an application. I don’t have answers yet. I don’t even really know what questions to ask. But I think I want to understand myself, not just impress people.
|
| 8 |
+
|
| 9 |
+
I guess that’s a start. Great job Bob!
|
requirments.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama_index
|
| 2 |
+
llama-index-embeddings-huggingface
|
| 3 |
+
llama-index-llms-google-genai
|
| 4 |
+
gradio
|
src/agent.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_index.core import SimpleDirectoryReader, Settings, VectorStoreIndex
|
| 2 |
+
from llama_index.core.node_parser import SentenceSplitter
|
| 3 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Agent:
|
| 7 |
+
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.streaming = False
|
| 10 |
+
|
| 11 |
+
def load_and_index_folder(self, folder_path, llm, embedding_model="BAAI/bge-small-en-v1.5"):
|
| 12 |
+
"""
|
| 13 |
+
Load and index documents from the specified folder path.
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
folder_path (str): The path to the folder containing documents.
|
| 17 |
+
embedding_model (str): The embedding model to use for indexing.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
# load documents
|
| 21 |
+
reader = SimpleDirectoryReader(folder_path)
|
| 22 |
+
documents = reader.load_data()
|
| 23 |
+
|
| 24 |
+
# parse nodes
|
| 25 |
+
parser = SentenceSplitter()
|
| 26 |
+
nodes = parser.get_nodes_from_documents(documents)
|
| 27 |
+
|
| 28 |
+
# setup vector store index
|
| 29 |
+
Settings.embed_model = HuggingFaceEmbedding(model_name=embedding_model)
|
| 30 |
+
index = VectorStoreIndex.from_documents(nodes)
|
| 31 |
+
|
| 32 |
+
# create query engine
|
| 33 |
+
Settings.llm = llm
|
| 34 |
+
self.index = index
|
| 35 |
+
self.query_engine = index.as_query_engine(streaming=self.streaming)
|
| 36 |
+
|
| 37 |
+
def query_index(self, query_text):
|
| 38 |
+
"""
|
| 39 |
+
Query the indexed documents.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
query_text (str): The query string.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
str: The response from the index.
|
| 46 |
+
"""
|
| 47 |
+
if not hasattr(self, 'index'):
|
| 48 |
+
raise ValueError("Index not found. Please load and index a folder first.")
|
| 49 |
+
|
| 50 |
+
response = self.query_engine.query(query_text)
|
| 51 |
+
|
| 52 |
+
return str(response)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|