-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tighearnán Carroll <[email protected]>
- Loading branch information
Tighearnán Carroll
and
Tighearnán Carroll
authored
May 18, 2023
1 parent
dab0178
commit f31124b
Showing
6 changed files
with
75 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build amd64 | ||
|
||
package renderer | ||
|
||
import ( | ||
"strings" | ||
"time" | ||
|
||
"github.com/armon/go-metrics" | ||
"github.com/robherley/guesslang-go/pkg/guesser" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
var guesslang *guesser.Guesser | ||
|
||
func init() { | ||
var err error | ||
guesslang, err = guesser.New() | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("failed to initialize guesslang") | ||
} | ||
} | ||
|
||
func Guess(content string) string { | ||
guessStart := time.Now() | ||
answer, err := guesslang.Guess(content) | ||
metrics.MeasureSince([]string{"guess", "duration"}, guessStart) | ||
if err != nil { | ||
log.Warn().Err(err).Msg("failed to guess the file type") | ||
return "" | ||
} | ||
|
||
return strings.ToLower(answer.Predictions[0].Language) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build arm64 | ||
|
||
package renderer | ||
|
||
func Guess(content string) string { | ||
// currently not supporting guessing in arm64 bc of libtensorflow requirements | ||
// https://github.com/robherley/snips.sh/issues/39 | ||
panic("not implemented") | ||
} |