Skip to content

Instantly share code, notes, and snippets.

View rshemet's full-sized avatar
💭
Debugging

rshemet

💭
Debugging
  • University of Oxford
  • United Kingdom
View GitHub Profile
@rshemet
rshemet / cactus-flutter-vlm-inference.dart
Created July 15, 2025 23:53
cactus-flutter-vlm-inference
import 'package:cactus/cactus.dart';
final vlm = await CactusVLM.init(
modelUrl: 'huggingface/gguf/vision-model/link', // URL to VLM GGUF
mmprojUrl: 'huggingface/gguf/mmproj/link', // URL to mmproj GGUF
);
final messages = [
ChatMessage(role: 'user', content: 'Describe what you see in this image.')
];
@rshemet
rshemet / cactus-flutter-text-generation.dart
Created July 15, 2025 23:48
Cactus Flutter text generation
import 'package:cactus/cactus.dart';
// pass in conversation history
final messages = [
ChatMessage(role: 'system', content: 'You are a helpful assistant.'),
ChatMessage(role: 'user', content: 'What is the capital of France?')
];
// run inference (lm is your previously initialized model)
final response = await lm.completion(
@rshemet
rshemet / cactus-flutter-lm-init.dart
Last active July 15, 2025 23:49
Cactus flutter CactusLM init
import 'package:cactus/cactus.dart';
final lm = await CactusLM.init(
modelUrl: 'https://huggingface.co/Cactus-Compute/Qwen3-600m-Instruct-GGUF/resolve/main/Qwen3-0.6B-Q8_0.gguf',
contextSize: 2048, // The context size for the model.
);
@rshemet
rshemet / cactus-react-native-vlm-inference.ts
Last active July 15, 2025 22:45
Cactus React Native VLM inference
import { CactusVLM } from 'cactus-react-native';
// Initialize the Vision Language Model.
const { vlm, error } = await CactusVLM.init({
model: '/path/to/vision-model.gguf',
mmproj: '/path/to/mmproj.gguf', // The projector file for the vision model.
});
if (error) {
console.error('Failed to initialize VLM:', error);
import { CactusLM } from 'cactus-react-native';
// Initialize the model. The localPath is the path to your previously downloaded model.
const { lm, error } = await CactusLM.init({
model: localPath,
n_ctx: 2048, // context window for your model
});
if (error) {
console.error('Failed to initialize model:', error);
@rshemet
rshemet / cactus-react-native-lm-completion.ts
Last active July 15, 2025 22:39
cactus react native LM completion
import { CactusLM } from 'cactus-react-native';
// pass in conversation history
const messages = [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is the capital of France?' }
];
// define inference parameters
const params = {
@rshemet
rshemet / cactus-model-download.ts
Last active July 15, 2025 22:30
Download cactus react native model
import RNFS from 'react-native-fs';
const modelUrl = 'https://huggingface.co/Cactus-Compute/Qwen3-600m-Instruct-GGUF/resolve/main/Qwen3-0.6B-Q8_0.gguf';
const localPath = `${RNFS.DocumentDirectoryPath}/${modelUrl.split('/').pop()}`;
// Download the model and log progress
await RNFS.downloadFile({
fromUrl: modelUrl,
toFile: localPath,
progress: res => console.log(`${(res.bytesWritten / res.contentLength * 100).toFixed(2)}%`),
@rshemet
rshemet / cactus-react-native-setup.sh
Created July 15, 2025 22:09
Cactus react native bash command
npm install cactus-react-native && npx pod-install
if __name__ == '__main__':
x = np.arange(50)[:, np.newaxis]
y = np.array([i + np.random.rand() for i in range(50)])[:, np.newaxis]
ols_test = Model(x, y)
ols_test.fit(intercept=True)
ols_test.predict()
ols_test.plot_predictions()
def plot_predictions(self):
plt.scatter(self.x, self.y, c='orange', label = 'Observed values')
plt.plot(self.x, self.y_hat, label = 'Fitted values')
plt.legend()
title_label = 'Fitted OLS Regression: intercept={}, slope={}'\
.format(np.round(self.betas[0][0],2), np.round(self.betas[1][0],2))
plt.title(label=title_label)
plt.show()