Skip to content

Commit 37759d6

Browse files
committed
Feat: works
1 parent 7c235a7 commit 37759d6

File tree

4 files changed

+108
-66
lines changed

4 files changed

+108
-66
lines changed

main.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,12 @@ import (
77
"github.com/S1ro1/popcorn-cli/src/cmd"
88
)
99

10-
func displayAsciiArt() {
11-
art := `
12-
_ __ _ ______ _
13-
| | / / | | | ___ \ | |
14-
| |/ / ___ _ __ _ __ ___ | | | |_/ / ___ _| |_
15-
| \ / _ \ '__| '_ \ / _ \| | | ___ \ / _ \| | __|
16-
| |\ \ __/ | | | | | __/| | | |_/ /| (_) | | |_
17-
\_| \_/\___|_| |_| |_|\___|_/ \____/ \___/|_|\__|
18-
19-
POPCORN CLI - GPU MODE
20-
21-
┌───────────────────────────────────────┐
22-
│ ┌─────┐ ┌─────┐ ┌─────┐ │
23-
│ │ooOoo│ │ooOoo│ │ooOoo│ │▒
24-
│ │oOOOo│ │oOOOo│ │oOOOo│ │▒
25-
│ │ooOoo│ │ooOoo│ │ooOoo│ ┌────────┐ │▒
26-
│ └─────┘ └─────┘ └─────┘ │████████│ │▒
27-
│ │████████│ │▒
28-
│ ┌────────────────────────┐ │████████│ │▒
29-
│ │ │ │████████│ │▒
30-
│ │ POPCORN GPU COMPUTE │ └────────┘ │▒
31-
│ │ │ │▒
32-
│ └────────────────────────┘ │▒
33-
│ │▒
34-
└───────────────────────────────────────┘▒
35-
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
36-
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
37-
`
38-
fmt.Println(art)
39-
}
4010

4111
func main() {
42-
_, ok := os.LookupEnv("POPCORN_API_URL")
43-
if !ok {
12+
13+
if os.Getenv("POPCORN_API_URL") == "" {
4414
fmt.Println("POPCORN_API_URL is not set. Please set it to the URL of the Popcorn API.")
4515
os.Exit(1)
4616
}
47-
displayAsciiArt()
4817
cmd.Execute()
4918
}

src/cmd/popcorn-cli.go

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
"github.com/charmbracelet/bubbles/list"
89
"github.com/charmbracelet/bubbles/spinner"
@@ -11,16 +12,11 @@ import (
1112
"github.com/S1ro1/popcorn-cli/src/models"
1213
"github.com/S1ro1/popcorn-cli/src/service"
1314

14-
// "github.com/S1ro1/popcorn-cli/src/utils"
15+
"github.com/S1ro1/popcorn-cli/src/utils"
1516

1617
tea "github.com/charmbracelet/bubbletea"
1718
)
1819

19-
var runnerItems = []list.Item{
20-
models.RunnerItem{TitleText: "Modal", DescriptionText: "Submit a solution to be evaluated on Modal runners.", Value: "modal"},
21-
models.RunnerItem{TitleText: "Github", DescriptionText: "Submit a solution to be evaluated on Github runners. This can take a little longer to spin up.", Value: "github"},
22-
}
23-
2420
var submissionModeItems = []list.Item{
2521
models.SubmissionModeItem{TitleText: "Test", DescriptionText: "Test the solution and give detailed results about passed/failed tests.", Value: "test"},
2622
models.SubmissionModeItem{TitleText: "Benchmark", DescriptionText: "Benchmark the solution, this also runs the tests and afterwards runs the benchmark, returning detailed timing results", Value: "benchmark"},
@@ -58,6 +54,17 @@ func (m model) Init() tea.Cmd {
5854
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5955
var cmd tea.Cmd
6056

57+
if len(m.gpusList.Items()) == 0 && m.modalState == models.ModelStateGpuSelection {
58+
gpus, err := service.GetListItems(func() ([]models.GpuItem, error) {
59+
return service.FetchAvailableGpus(m.selectedLeaderboard)
60+
})
61+
if err != nil {
62+
m.SetError(fmt.Sprintf("Error fetching GPUs: %s", err))
63+
return m, tea.Quit
64+
}
65+
m.gpusList = list.New(gpus, list.NewDefaultDelegate(), m.width-2, m.height-2)
66+
m.gpusList.SetSize(m.width-2, m.height-2)
67+
}
6168
if !m.finishedOkay {
6269
return m, tea.Quit
6370
}
@@ -72,19 +79,26 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7279
case models.ModelStateLeaderboardSelection:
7380
if i := m.leaderboardsList.SelectedItem(); i != nil {
7481
m.selectedLeaderboard = i.(models.LeaderboardItem).TitleText
75-
m.modalState = models.ModelStateGpuSelection
76-
gpus, err := service.GetListItems(func() ([]models.GpuItem, error) {
77-
return service.FetchAvailableGpus(m.selectedLeaderboard)
78-
})
79-
if err != nil {
80-
m.SetError(fmt.Sprintf("Error fetching GPUs: %s", err))
81-
return m, tea.Quit
82-
}
83-
if len(gpus) == 0 {
84-
m.SetError("No GPUs available for this leaderboard.")
85-
return m, tea.Quit
82+
// No gpu selected in popcorn directives, fetch gpus and move to gpu selection
83+
if m.selectedGpu == "" {
84+
gpus, err := service.GetListItems(func() ([]models.GpuItem, error) {
85+
return service.FetchAvailableGpus(m.selectedLeaderboard)
86+
})
87+
if err != nil {
88+
m.SetError(fmt.Sprintf("Error fetching GPUs: %s", err))
89+
return m, tea.Quit
90+
}
91+
if len(gpus) == 0 {
92+
m.SetError("No GPUs available for this leaderboard.")
93+
return m, tea.Quit
94+
}
95+
m.gpusList = list.New(gpus, list.NewDefaultDelegate(), m.width-2, m.height-2)
96+
m.gpusList.SetSize(m.width-2, m.height-2)
97+
m.modalState = models.ModelStateGpuSelection
98+
} else {
99+
m.modalState = models.ModelStateSubmissionModeSelection
100+
m.submissionModeList.SetSize(m.width-2, m.height-2)
86101
}
87-
m.gpusList = list.New(gpus, list.NewDefaultDelegate(), m.width-2, m.height-2)
88102
}
89103
case models.ModelStateGpuSelection:
90104
if i := m.gpusList.SelectedItem(); i != nil {
@@ -203,30 +217,51 @@ func Execute() {
203217
return
204218
}
205219

206-
// popcornDirectives, err := utils.GetPopcornDirectives(filepath)
207-
// if err != nil {
208-
// fmt.Println("Error fetching popcorn directives:", err)
209-
// return
210-
// }
220+
popcornDirectives, err := utils.GetPopcornDirectives(filepath)
221+
if err != nil {
222+
fmt.Println("Error:", err)
223+
var input string
224+
fmt.Scanln(&input)
225+
if strings.ToLower(input) != "y" {
226+
return
227+
}
228+
}
229+
230+
var modalState models.ModelState
231+
if popcornDirectives.LeaderboardName != "" && len(popcornDirectives.Gpus) > 0 {
232+
modalState = models.ModelStateSubmissionModeSelection
233+
} else if popcornDirectives.LeaderboardName != "" {
234+
modalState = models.ModelStateGpuSelection
235+
} else {
236+
modalState = models.ModelStateLeaderboardSelection
237+
}
238+
239+
var selectedGpu string
240+
if len(popcornDirectives.Gpus) > 0 {
241+
selectedGpu = popcornDirectives.Gpus[0]
242+
}
211243

212244
leaderboardItems, err := service.GetListItems(service.FetchLeaderboards)
213245
if err != nil {
214246
fmt.Println("Error fetching leaderboards:", err)
215-
return
247+
216248
}
217249

218250
s := spinner.New()
219251
s.Spinner = spinner.Dot
220252
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
221253

222254
m := model{
223-
filepath: filepath,
224-
leaderboardsList: list.New(leaderboardItems, list.NewDefaultDelegate(), 0, 0),
225-
submissionModeList: list.New(submissionModeItems, list.NewDefaultDelegate(), 0, 0),
226-
spinner: s,
227-
modalState: models.ModelStateLeaderboardSelection,
228-
finishedOkay: true,
229-
finalStatus: "",
255+
filepath: filepath,
256+
leaderboardsList: list.New(leaderboardItems, list.NewDefaultDelegate(), 0, 0),
257+
submissionModeList: list.New(submissionModeItems, list.NewDefaultDelegate(), 0, 0),
258+
gpusList: list.New([]list.Item{}, list.NewDefaultDelegate(), 0, 0),
259+
spinner: s,
260+
modalState: modalState,
261+
finishedOkay: true,
262+
finalStatus: "",
263+
selectedLeaderboard: popcornDirectives.LeaderboardName,
264+
selectedGpu: selectedGpu,
230265
}
231266
m.leaderboardsList.Title = "Leaderboards"
232267

@@ -238,6 +273,7 @@ func Execute() {
238273
}
239274

240275
m, ok := finalModel.(model)
276+
utils.DisplayAsciiArt()
241277
if ok && m.finishedOkay {
242278
fmt.Printf("\nResult:\n\n%s\n", m.finalStatus)
243279
} else if ok && !m.finishedOkay {

src/models/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package models
22

33
type LeaderboardItem struct {
4-
TitleText string
4+
TitleText string
55
TaskDescription string
66
}
77

src/utils/utils.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"fmt"
45
"os"
56
"strings"
67
)
@@ -11,6 +12,7 @@ type PopcornDirectives struct {
1112
}
1213

1314
func GetPopcornDirectives(filepath string) (*PopcornDirectives, error) {
15+
var err error = nil
1416
content, err := os.ReadFile(filepath)
1517

1618
var gpus []string = []string{}
@@ -37,9 +39,44 @@ func GetPopcornDirectives(filepath string) (*PopcornDirectives, error) {
3739
}
3840
}
3941

42+
if len(gpus) > 1 {
43+
err = fmt.Errorf("multiple GPUs are not yet supported, continue with the first gpu? (%s) [y/N]", gpus[0])
44+
gpus = []string{gpus[0]}
45+
}
46+
4047
return &PopcornDirectives{
4148
LeaderboardName: leaderboard_name,
4249
Gpus: gpus,
43-
}, nil
50+
}, err
4451
}
4552

53+
func DisplayAsciiArt() {
54+
art := `
55+
_ __ _ ______ _
56+
| | / / | | | ___ \ | |
57+
| |/ / ___ _ __ _ __ ___ | | | |_/ / ___ _| |_
58+
| \ / _ \ '__| '_ \ / _ \| | | ___ \ / _ \| | __|
59+
| |\ \ __/ | | | | | __/| | | |_/ /| (_) | | |_
60+
\_| \_/\___|_| |_| |_|\___|_/ \____/ \___/|_|\__|
61+
62+
POPCORN CLI - GPU MODE
63+
64+
┌───────────────────────────────────────┐
65+
│ ┌─────┐ ┌─────┐ ┌─────┐ │
66+
│ │ooOoo│ │ooOoo│ │ooOoo│ │▒
67+
│ │oOOOo│ │oOOOo│ │oOOOo│ │▒
68+
│ │ooOoo│ │ooOoo│ │ooOoo│ ┌────────┐ │▒
69+
│ └─────┘ └─────┘ └─────┘ │████████│ │▒
70+
│ │████████│ │▒
71+
│ ┌────────────────────────┐ │████████│ │▒
72+
│ │ │ │████████│ │▒
73+
│ │ POPCORN GPU COMPUTE │ └────────┘ │▒
74+
│ │ │ │▒
75+
│ └────────────────────────┘ │▒
76+
│ │▒
77+
└───────────────────────────────────────┘▒
78+
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
79+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
80+
`
81+
fmt.Println(art)
82+
}

0 commit comments

Comments
 (0)