Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push to production #435

Merged
merged 20 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ PythonRpcServer/ct_pb2.py
/old--dot.env
/docker-compose.yml
/PythonRpcServer/corpus_count.json
DevExperiments/LocalEnvironmentVariables.txt
85 changes: 60 additions & 25 deletions ClassTranscribeDatabase/CommonUtils.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using ClassTranscribeDatabase.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ClassTranscribeDatabase
Expand Down Expand Up @@ -165,17 +167,29 @@
return name;
}
public static string ToCourseOfferingSubDirectory(CTDbContext ctx, Entity entity) {
#nullable enable
String? path = GetRelatedCourseOfferingFilePath(ctx, entity);

if( !string.IsNullOrEmpty(path ) ) {
return path;
#nullable enable
try
{
String? path = GetRelatedCourseOfferingFilePath(ctx, entity);

if (!string.IsNullOrEmpty(path))
{
return path;
}
} catch (Exception ignored)
{
Console.WriteLine(ignored);
}
#nullable disable
return "/data/"; //legacy, pre 2022, default = everything is stored in the same directory
// we could still get here if something in the model has been deleted.
}
#nullable enable
public static string GetRelatedCourseOfferingFilePath(CTDbContext ctx, Entity entity)
{
return GetRelatedCourseOfferingFilePathAsync(ctx, entity).GetAwaiter().GetResult();

Check warning on line 190 in ClassTranscribeDatabase/CommonUtils.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference return.

Check warning on line 190 in ClassTranscribeDatabase/CommonUtils.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference return.
}
#nullable enable
public static string? GetRelatedCourseOfferingFilePath(CTDbContext ctx, Entity entity)
public static async Task<string?> GetRelatedCourseOfferingFilePathAsync(CTDbContext ctx, Entity entity)
{
// the only thing that we can trust exists on the given the entity Id
// Drop recursion... this may reduce the number of SQL calls
Expand All @@ -186,40 +200,61 @@
switch (entity)
{
case CourseOffering co:
return ctx.CourseOfferings.Where(co2 => co2.Id == co.Id).OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;
return co.FilePath;

case Course c:
return ctx.CourseOfferings.Where(c2 => c2.CourseId == c.Id)
.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;
return (await ctx.CourseOfferings.OrderBy(co => co.CreatedAt).FirstOrDefaultAsync(co=>co.CourseId == c.Id))?.FilePath;

case Media m:
return ctx.Medias.FirstOrDefault(m2=>m2.Id == m.Id ).Playlist.Offering
.CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;
return await playlistIdToFilePath(ctx, m.PlaylistId);

case Offering o:
return ctx.CourseOfferings.Where(co2 => co2.OfferingId == o.Id)
.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;
return (await ctx.CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefaultAsync(co2 => co2.OfferingId == o.Id))?.FilePath;

case Playlist p:
return ctx.Playlists.FirstOrDefault(p2=>p2.Id == p.Id ).Offering
.CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;

return await playlistIdToFilePath(ctx, p.Id);

case Transcription t:
return ctx.Transcriptions.FirstOrDefault(t2=>t2.Id == t.Id)?.Video
.Medias.OrderBy(co=>co.CreatedAt).FirstOrDefault()
?.Playlist.Offering
.CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;
{
var playlistId = (await ctx.Transcriptions.Include(t => t.Video).ThenInclude(v => v.Medias).FirstOrDefaultAsync(t2 => t2.Id == t.Id))
?.Video.Medias.OrderBy(co => co.CreatedAt).Select(m => m.PlaylistId).FirstOrDefault();
return await playlistIdToFilePath(ctx, playlistId);
}
// return ctx.Transcriptions.FirstOrDefault(t2=>t2.Id == t.Id)?.Video
// .Medias.OrderBy(co=>co.CreatedAt).FirstOrDefault()
// ?.Playlist.Offering
// .CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;

case Video v:
return ctx.Medias.OrderBy(co=>co.CreatedAt).FirstOrDefault(m2=>m2.VideoId == v.Id )
.Playlist.Offering
.CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;
{
var playlistId = (await ctx.Medias.OrderBy(co => co.CreatedAt).FirstOrDefaultAsync(m => m.VideoId == v.Id))?.PlaylistId;
return await playlistIdToFilePath(ctx, playlistId);
}
// return ctx.Medias.OrderBy(co=>co.CreatedAt).FirstOrDefault(m2=>m2.VideoId == v.Id )
// .Playlist.Offering
// .CourseOfferings.OrderBy(co=>co.CreatedAt).FirstOrDefault()?.FilePath;

default:
throw new InvalidOperationException($"GetRelatedCourseOffering not implemented for type {entity.GetType()} (Object ID: {entity.Id})");
}

}
#nullable disable

private async static Task<string?> playlistIdToFilePath(CTDbContext ctx, string? playlistId)
{
if (string.IsNullOrEmpty(playlistId)) return "";

var playlist = (await ctx.Playlists.Include(p => p.Offering).FirstOrDefaultAsync(p => p.Id == playlistId));
var offeringId = playlist?.Offering?.Id ?? "";
return offeringId.Length >0 ? await offeringIdToFilePath(ctx, offeringId) : "";
}
private async static Task<string?> offeringIdToFilePath(CTDbContext ctx, string? offeringId)
{
if (string.IsNullOrEmpty(offeringId)) return "";

var courseoffering = (await ctx.CourseOfferings.OrderBy(co => co.CreatedAt).FirstOrDefaultAsync(co => co.OfferingId == offeringId));
return courseoffering?.FilePath ?? "";
}
#nullable disable
}
}
7 changes: 7 additions & 0 deletions ClassTranscribeDatabase/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public class AppSettings

public string DIGEST_CALCULATION_METHOD { get; set; } = "";

public string LLAVA_PATH { get; set; } = "/llava/llava-v1.5-7b-q4.llamafile";
public string LLAVA_ARGS { get; set; } = "--threads {cpuCount} -m llava-v1.5-7b-Q4_K.gguf --mmproj llava-v1.5-7b-mmproj-Q4_0.gguf --temp 0.0 --silent-prompt --image \"{imagePath}\" --escape -p \"{prompt}\"";
public string LLAVA_PROMPT { get; set; } = "### User: I am blind and listening to a university lecture video. What is in this image, that has been extracted from the lecture video? Be concise. Do your best to describe only the technical content of the image that is relevant to learning. Do not add opinions about the image.\n### Assistant:";

public string LLAVA_LOG_STREAMS { get; set; } = "out,err";
public string LLAVA_USESHELL { get; set; } = "";

}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ClassTranscribeDatabase/Services/Slack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
_logger = logger;

// ignore
string url = _appSettings.SLACK_WEBHOOK_URL.Trim();
string url = _appSettings.SLACK_WEBHOOK_URL?.Trim()??"";
if (url.Length > 0 && !url.Contains("<ADD WEBHOOK URL HERE>"))
{
_uri = new Uri(url);
Expand Down Expand Up @@ -79,7 +79,7 @@
}
try
{
using (WebClient client = new WebClient())

Check warning on line 82 in ClassTranscribeDatabase/Services/Slack.cs

View workflow job for this annotation

GitHub Actions / Build

'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 82 in ClassTranscribeDatabase/Services/Slack.cs

View workflow job for this annotation

GitHub Actions / Build

'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.' (https://aka.ms/dotnet-warnings/SYSLIB0014)
{
NameValueCollection data = new NameValueCollection();
data["payload"] = payloadJson;
Expand Down
10 changes: 8 additions & 2 deletions ClassTranscribeServer.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28902.138
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassTranscribeServer", "ClassTranscribeServer\ClassTranscribeServer.csproj", "{E4C52518-A6B4-42B0-8A02-DC1BFBE9CD89}"
EndProject
Expand All @@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\Unit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAzureCognitiveServices", "TestAzureCognitiveServices\TestAzureCognitiveServices.csproj", "{DA560288-98FC-4233-8CD5-252F8570CBFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestRemoteLLM", "TestRemoteLLM\TestRemoteLLM.csproj", "{9D9DB7A1-DBDA-49DF-9D31-D39846BABE30}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -55,6 +57,10 @@ Global
{DA560288-98FC-4233-8CD5-252F8570CBFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA560288-98FC-4233-8CD5-252F8570CBFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA560288-98FC-4233-8CD5-252F8570CBFB}.Release|Any CPU.Build.0 = Release|Any CPU
{9D9DB7A1-DBDA-49DF-9D31-D39846BABE30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D9DB7A1-DBDA-49DF-9D31-D39846BABE30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D9DB7A1-DBDA-49DF-9D31-D39846BABE30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D9DB7A1-DBDA-49DF-9D31-D39846BABE30}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 3 additions & 2 deletions DevExperiments/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ static void Main(string[] args)
{
builder.AddConsole();
builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>
("", LogLevel.Warning);
builder.AddApplicationInsights(configuration.GetValue<string>("APPLICATION_INSIGHTS_KEY"));
("", LogLevel.Warning);
//builder.AddApplicationInsights(configuration.GetValue<string>("APPLICATION_INSIGHTS_KEY"));
})
.AddOptions()
.Configure<AppSettings>(configuration)
//.AddDbContext<CTDbContext>(options => options.UseNpgsql(CTDbContext.ConnectionStringBuilder()))
.AddDbContext<CTDbContext>(options => options.UseLazyLoadingProxies().UseNpgsql(CTDbContext.ConnectionStringBuilder()))
.AddScoped<SlackLogger>()
.AddSingleton<MSTranscriptionService>()
Expand Down
88 changes: 87 additions & 1 deletion DevExperiments/TempCode.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using ClassTranscribeDatabase;
using ClassTranscribeDatabase.Migrations;
using ClassTranscribeDatabase.Models;
using ClassTranscribeDatabase.Services;
using ClassTranscribeDatabase.Services.MSTranscription;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Newtonsoft.Json.Linq;
using NpgsqlTypes;
using System;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;

namespace DevExperiments
{
Expand All @@ -22,9 +29,88 @@ public TempCode(CTDbContext c, MSTranscriptionService transcriptionService, RpcC
_rpcClient = rpcClient;
}

public async Task ReadEntity()
{
Transcription transcription = context.Transcriptions.FirstOrDefault((t=>t.Id == "a3013ae4-869a-4de4-97d2-101af3ef75d7"));
Video video = context.Videos.OrderByDescending(co => co.CreatedAt).FirstOrDefault();
Playlist playlist = context.Playlists.OrderByDescending(co => co.CreatedAt).FirstOrDefault();
CourseOffering co = context.CourseOfferings.OrderByDescending(co => co.CreatedAt).FirstOrDefault();
Offering off = context.Offerings.OrderByDescending(co => co.CreatedAt).FirstOrDefault();
Media media = context.Medias.OrderByDescending(co => co.CreatedAt).FirstOrDefault();

List<Entity> items = new List<Entity>();
items.Add(video);
items.Add(playlist);
items.Add(transcription);
items.Add(co);
items.Add(off);
items.Add(media);

foreach(var entity in items) {
var filePath1 = CommonUtils.ToCourseOfferingSubDirectory(context, entity);
Console.WriteLine(filePath1);
}

}
public async Task ReadEntity2()
{
int count = await context.Transcriptions.CountAsync();
Console.WriteLine($"Count: {count}");
var tid1 = "4aa9e224-75f0-4775-a531-a5b0c99693f0"; // playlist deleted
var tid2 = "a3013ae4-869a-4de4-97d2-101af3ef75d7";
var tid3 = "a3013ae4-869a-4de4-97d2-101af3ef75d7"; // "8c4f01ec-5620-49e5-aa33-89cdfa37ac55"; // "4d47ee07-6bbc-47b7-8da5-6a80cf006f1c";
var tid = tid1;
var playlistId = (await context.Transcriptions.Include(t => t.Video).ThenInclude(v=>v.Medias).FirstOrDefaultAsync(t2 => t2.Id == tid))
?.Video.Medias.OrderBy(co => co.CreatedAt).Select(m=>m.PlaylistId).FirstOrDefault();
var offeringId =(await context.Playlists.Include(p => p.Offering).FirstOrDefaultAsync(p => p.Id == playlistId)) ?.Offering.Id;
CourseOffering courseoff = (await context.CourseOfferings.Where(co => co.OfferingId == offeringId).OrderBy(co => co.CreatedAt).FirstOrDefaultAsync());
string filepath = courseoff?.FilePath;

Console.WriteLine($"# playlistId isnull {playlistId == null},{playlistId}");
Console.WriteLine($"# Offering isnull {offeringId == null},{offeringId}");
Console.WriteLine($"courseoff isnull:{courseoff == null}, {courseoff} ");
Console.WriteLine($"FilePath isnull:{filepath == null}, {filepath} ");


/* string filepath = context.Transcriptions.FirstOrDefault(t2 => t2.Id == tid)?.Video
.Medias.OrderBy(co => co.CreatedAt).FirstOrDefault()
?.Playlist.Offering
.CourseOfferings.OrderBy(co => co.CreatedAt).FirstOrDefault()?.FilePath; */
// Console.WriteLine($"Path:{filepath}");
return;
}
void ignore() {
// Transcription t1 = context.Transcriptions.Include("Video").FirstOrDefault(t2 => t2.Id == tid);

//Console.WriteLine($"T found {t1.Id} -> {t1.VideoId}");
//Video v2 = context.Videos.Find( t1.VideoId);
//Console.WriteLine($"V2 found {v2.Id}");

// Video v1 = t1.Video;

// Console.WriteLine($"V1 found {v1.Id}");

// List<Media> m1 = context.Transcriptions.FirstOrDefault(t2 => t2.Id == tid)?.Video.Medias;

// Media m1 = context.Transcriptions.Include(t => t.Video.Medias).FirstOrDefault(t2 => t2.Id == tid)?.Video.Medias.OrderBy(co => co.CreatedAt).FirstOrDefault();
// Console.WriteLine($"# Media found {m1}");

// Offering o1 = context.Playlists.Include(p => p.Offering).FirstOrDefault(p => p.Id == m1.PlaylistId).Offering;
// Console.WriteLine($"# Offering found {o1}");

// var filepath = context.Playlists.Include(p=>p.Offering.CourseOfferings).FirstOrDefault(p => p.Id == m1.PlaylistId).Offering.CourseOfferings.OrderBy(co => co.CreatedAt).FirstOrDefault()?.FilePath;

//Offering o1 = context.Transcriptions.FirstOrDefault(t2 => t2.Id == tid)?.Video
// .Medias.OrderBy(co => co.CreatedAt).FirstOrDefault()
// ?.Playlist.Offering;


}
public void Temp()
{
TempAsync().GetAwaiter().GetResult();
ReadEntity().GetAwaiter().GetResult(); ;

//TempAsync().GetAwaiter().GetResult();
}

private async Task TempAsync()
Expand Down
16 changes: 15 additions & 1 deletion TaskEngine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ RUN dotnet publish TaskEngine.csproj -c Release -o /app --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim as publish_base
# FROM mcr.microsoft.com/dotnet/core/runtime:3.1.3-bionic as publish_base
RUN apt-get update && apt-get install -y build-essential libasound2 wget netcat-traditional && apt-get -q update
# Install prerequisites for Azure Speech Services: build-essential libssl-dev ca-certificates libasound2 wget
# See https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstarts/setup-platform

RUN apt-get update && apt-get install -y build-essential libssl-dev ca-certificates libasound2 wget && \
apt-get install -y netcat-traditional && apt-get -q update

# Microsoft 8.0 issue: https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/2204
# This will install OpenSSL 1.1.1 because it is needed by the Speech SDK.
RUN \
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb && \
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl-dev_1.1.1f-1ubuntu2.20_amd64.deb && \
dpkg -i libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb && \
dpkg -i libssl-dev_1.1.1f-1ubuntu2.20_amd64.deb && \
rm libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb libssl-dev_1.1.1f-1ubuntu2.20_amd64.deb


FROM publish_base as publish
WORKDIR /
Expand Down
1 change: 1 addition & 0 deletions TaskEngine/TaskEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="NEST" Version="7.17.5" />
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" />
<PackageReference Include="RestSharp" Version="110.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions TaskEngine/TaskEngine.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TaskEngine", "TaskEngine.csproj", "{09720F43-452A-43D0-BE7E-AAE2CF822AA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09720F43-452A-43D0-BE7E-AAE2CF822AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09720F43-452A-43D0-BE7E-AAE2CF822AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09720F43-452A-43D0-BE7E-AAE2CF822AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09720F43-452A-43D0-BE7E-AAE2CF822AA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {83861AB8-4CDE-41B0-8309-63BD076F3EA6}
EndGlobalSection
EndGlobal
Loading
Loading