Skip to content

Commit

Permalink
Simplifying configuration and updating Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerBarreto committed May 7, 2023
1 parent ac67c90 commit f06db72
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 49 deletions.
2 changes: 1 addition & 1 deletion AI.YouTubeSummarizer/AI.YouTubeSummarizer.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>0.1.0</Version>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>AI.YouTubeSummarizer</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>a746658a-2ee0-448d-b156-5916b1b2d051</UserSecretsId>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'" >
Expand Down
14 changes: 1 addition & 13 deletions AI.YouTubeSummarizer/ConfigurationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,5 @@ public class ConfigurationSettings
public string OPENAI_KEY { get; set; }

[JsonPropertyName("languages")]
public IReadOnlyList<LanguageConfig> Languages { get; set; }
}

public class LanguageConfig
{
[JsonPropertyName("alias")]
public string Alias { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("prompt")]
public string Prompt { get; set; }
public IReadOnlyList<string> Languages { get; set; }
}
2 changes: 1 addition & 1 deletion AI.YouTubeSummarizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static ConfigurationSettings ConfigureSettings()
{
var builder = new ConfigurationBuilder()
.AddUserSecrets<ConfigurationSettings>()
.AddJsonFile("config.json", optional: false, reloadOnChange: true)
.AddJsonFile("config.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();

var configuration = builder.Build();
Expand Down
19 changes: 7 additions & 12 deletions AI.YouTubeSummarizer/YouTubeSummarizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class YouTubeSummarizer
private double _lastStartTime;
private TranscriptItem _lastItem;
private string _videoTitle;
private LanguageConfig _selectedLanguage;
private string _selectedLanguage;

public YouTubeSummarizer(ConfigurationSettings configData)
{
Expand All @@ -40,7 +40,7 @@ public async Task SummarizeVideoAsync(string youTubeUrl)
--------------------------------------------------");
IChatCompletion chatCompletion = new OpenAIChatCompletion("gpt-3.5-turbo", this._configData.OPENAI_KEY);

var chat = (OpenAIChatHistory)chatCompletion.CreateNewChat(this._selectedLanguage.Prompt);
var chat = (OpenAIChatHistory)chatCompletion.CreateNewChat("You are a summarizer, I will provide you any language truncated text and you are going to summarize it for me in " + this._selectedLanguage);

if (this._transcriptItems.Count > 0)
{
Expand All @@ -62,7 +62,7 @@ private void FetchTranscriptItems(string videoId)
TranscriptList transcriptResult = youTubeTranscriptApi.ListTranscripts(videoId);
this._videoTitle = transcriptResult.VideoTitle;

foreach (var item in transcriptResult.FindTranscriptOrDefaultToExisting("en", "pt").Fetch())
foreach (var item in transcriptResult.FindTranscriptOrDefaultToExisting("en").Fetch())
{
this._transcriptItems.Enqueue(item);
}
Expand Down Expand Up @@ -140,12 +140,7 @@ internal void PromptForLanguages()
if (this._configData.Languages is null || this._configData.Languages.Count == 0)
{
Console.WriteLine("⚠️ No language configuration detected.\n\nDefaulting to English.\n");
this._selectedLanguage = new LanguageConfig
{
Alias = "en",
Description = "English",
Prompt = "You are a summarizer, every text I provide you are going to summarize it for me"
};
this._selectedLanguage = "English";

return;
}
Expand All @@ -155,7 +150,7 @@ internal void PromptForLanguages()
Console.WriteLine("Please select the language you want to use for the summarization: ");
for (int i = 0; i < this._configData.Languages.Count; i++)
{
Console.WriteLine($"{i + 1} - {this._configData.Languages[i].Description}");
Console.WriteLine($"{i + 1} - {this._configData.Languages[i]}");
}
Console.Write("Option: ");

Expand All @@ -168,7 +163,7 @@ internal void PromptForLanguages()
{
this._selectedLanguage = this._configData.Languages[optionNumber - 1];

Console.WriteLine($"\nSelected language: {this._selectedLanguage.Description}\n");
Console.WriteLine($"\nSelected language: {this._selectedLanguage}\n");
return;
}
}
Expand All @@ -178,7 +173,7 @@ internal void PromptForLanguages()
}

this._selectedLanguage = this._configData.Languages[0];
Console.WriteLine($"ℹ️ Only one language configuration detected.\n\nAuto-Selected language: {this._selectedLanguage.Description}\n");
Console.WriteLine($"ℹ️ Only one language configuration detected.\n\nAuto-Selected language: {this._selectedLanguage}\n");
return;
}
}
18 changes: 1 addition & 17 deletions AI.YouTubeSummarizer/config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
{
"languages": [
{
"alias": "en",
"description": "English",
"prompt": "You are a summarizer, I will provide you any language truncated text and you are going to summarize it for me in English"
},
{
"alias": "pt",
"description": "Português",
"prompt": "You are a summarizer, I will provide you any language truncated text and you are going to summarize it for me in Portuguese"
},
{
"alias": "kr",
"description": "한국어",
"prompt": "You are a summarizer, I will provide you any language truncated text and you are going to summarize it for me in Korean"
}
]
"languages": ["English", "Português", "한국어"]
}
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

Summarize your Youtube Videos quickly using your preferred language.

## End user - Installation
## End user - Setup

Get the released version executable. Here:

1. Setup your OpenAI API Key
##### Setup your OpenAI API Key

Create an environment variable named `OPENAI_KEY` with your OpenAI API Key.
Create an environment variable named `OPENAI_KEY` with your OpenAI API Key.

##### Optionally you can use your own preferred languages to summarize

Change `config.json` file with your preferred languages and leave it in the same folder as the application.

```json
{
"languages": ["English", "Your Language 1", "Your Language 2", ...]
}
```

## Developer Setup

Expand All @@ -27,16 +37,24 @@ dotnet user-secrets init
dotnet user-secrets set "OPENAI_KEY" "<your key>"
```

### Running / Development
Running / Debugging

```powershell
dotnet run
```

### Deploying / Publishing

Windows:

```powershell
dotnet publish -r win-x64 -c Release
```

Linux:

```powershell
dotnet publish -c Release
dotnet publish -r linux-x64 -c Release -p:PublishReadyToRun=true
```

## Projects Used
Expand Down

0 comments on commit f06db72

Please sign in to comment.