Skip to content

Commit

Permalink
fix: Mind maps were corrected and sent to the user in html format
Browse files Browse the repository at this point in the history
- Also updated the time formater

- Integrates with docker for deployment
  • Loading branch information
miguelcsx committed Jun 7, 2024
1 parent 9668f98 commit 66e433c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 27 deletions.
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Use an official Python runtime as a parent image
FROM python:3.10-slim AS base

# Install git to handle submodules
RUN apt-get update && apt-get install -y git

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Create and activate a virtual environment
RUN python -m venv /venv
ENV PATH="/venv/bin:$PATH"

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Use an official Node.js runtime as a parent image
FROM node:18-slim AS node_base

# Install npx globally
RUN npm install -g npx --force

# Use the base image
FROM base AS final

# Set the working directory in the container
WORKDIR /app

# Copy the installed npx from the Node.js image
COPY --from=node_base /usr/local/bin/npx /usr/local/bin/npx

# Copy the rest of the application code
COPY . .

# Copy the .env file into the container
COPY .env .

# Initialize and update git submodules
RUN git submodule init && git submodule update

# Define the command to run the application
CMD ["python", "-m", "app.main"]
6 changes: 5 additions & 1 deletion app/server/commands/ai_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ async def generate_map(self, ai: TextModel, text: str, user_id: str) -> None:
file.write(response)

# Create the visual mind map
run_npx_command("markmap-cli", "--no-open", "--no-toolbar", "--offline", "-o", mindmap_path, f"{mindmap_path}.html")
run_npx_command("markmap-cli", "--no-open", "--no-toolbar", mindmap_path, "--offline", "-o", f"{mindmap_path}.html")

os.remove(mindmap_path)

return f"{mindmap_path}.html"

def get_help(self):
return {
Expand Down
4 changes: 3 additions & 1 deletion app/server/commands/command_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ async def ai_mindmap(
) -> None:
sub_command = "mindmap"
await interaction.response.send_message(embed=discord.Embed(title="Creating mind map"))
await bot.ai_command.execute(sub_command, text, interaction.user.id)
path = await bot.ai_command.execute(sub_command, text, interaction.user.id)
await interaction.user.send(file=discord.File(path))
await interaction.followup.send("Mind map created.")

bot.tree.add_command(ai)

Expand Down
8 changes: 5 additions & 3 deletions app/server/events/study_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def format_time(minutes: float) -> str:

# Extract days, hours, minutes, and seconds
days = td.days
hours = td.seconds // 3600
minutes = (td.seconds % 3600) // 60
seconds = td.seconds % 60
remaining_seconds = td.seconds
hours = remaining_seconds // 3600
remaining_seconds %= 3600
minutes = remaining_seconds // 60
seconds = remaining_seconds % 60

# Build the formatted string
parts = []
Expand Down
2 changes: 1 addition & 1 deletion app/sources/generative/text_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def summarize(self, text: str, type: str) -> str:
return result.content

def create_mindmap(self, text: str) -> str:
prompt = f"Create a markdown mind map from the following text: {text} to use with markmap"
prompt = f"Create a markdown contextualizing the main ideas to create a mind map for the following text: {text}"
result = self.llm.invoke(prompt)
return result.content
20 changes: 0 additions & 20 deletions app/utils/parser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
# aura/app/utils/parser.py

import cairosvg


def convert_html_to_svg(html: str, output_file: str) -> None:
"""
Convert HTML to SVG
"""
with open(html, "r", encoding="uft-8") as file:
html_content = file.read()
cairosvg.svg2svg(html_content, write_to=output_file)


def convert_html_to_png(html: str, output_file: str) -> None:
"""
Convert HTML to PNG
"""
with open(html, "r", encoding="utf-8") as file:
html_content = file.read()
cairosvg.svg2png(html_content, write_to=output_file)
9 changes: 8 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ astroid==3.1.0
async-timeout==4.0.3
attrs==23.2.0
beautifulsoup4==4.12.3
Brotli==1.1.0
bs4==0.0.2
cachetools==5.3.3
cairocffi==1.7.0
CairoSVG==2.7.1
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
Expand All @@ -22,6 +23,7 @@ distro==1.9.0
exceptiongroup==1.2.0
filelock==3.14.0
flake8==7.0.0
fonttools==4.53.0
frozenlist==1.4.1
fsspec==2024.3.1
google-ai-generativelanguage==0.6.2
Expand All @@ -35,6 +37,7 @@ greenlet==3.0.3
grpcio==1.62.2
grpcio-status==1.62.2
h11==0.14.0
html5lib==1.1
httpcore==1.0.5
httplib2==0.22.0
httpx==0.27.0
Expand Down Expand Up @@ -69,14 +72,17 @@ pycodestyle==2.11.1
pycparser==2.22
pydantic==2.7.1
pydantic_core==2.18.2
pydyf==0.10.0
pyflakes==3.2.0
pylint==3.1.0
pyparsing==3.1.2
pyphen==0.15.0
pytest==8.1.1
python-dotenv==1.0.1
PyYAML==6.0.1
requests==2.31.0
rsa==4.9
six==1.16.0
sniffio==1.3.1
soupsieve==2.5
SQLAlchemy==2.0.29
Expand All @@ -93,3 +99,4 @@ urllib3==2.2.1
webencodings==0.5.1
wikipedia==1.4.0
yarl==1.9.4
zopfli==0.2.3

0 comments on commit 66e433c

Please sign in to comment.