File size: 3,415 Bytes
3511864
 
d5ee2a4
3511864
 
 
 
 
 
 
 
 
 
6666806
133562c
6666806
 
 
 
 
 
 
133562c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6666806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133562c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
title: Refsheet Chat
emoji: 💬
colorFrom: gray
colorTo: green
sdk: gradio
sdk_version: 5.21.0
app_file: app.py
pinned: false
license: mit
short_description: Chat with a character via reference sheet!
---

# RefSheet Chat -- Chat with a character via reference sheet

Upload a reference sheet of a character, RefSheet Chat will try to understand the character through the reference sheet, and talk to you as that character. RefSheet Chat can run locally to ensure privacy.

Website: <https://refsheet.chat>

Tutorial slide (in Chinese) can be found in <https://snowkylin.github.io/talks/>

RefSheet Chat is a demo of [Gemma 3](https://blog.google/technology/developers/gemma-3/), demonstrating its excellent vision and multilingual capability.

## Environment Configuration

Register an account on [HuggingFace](https://huggingface.co)

Submit a Gemma Access Request from <https://huggingface.co/google/gemma-3-4b-it>. The access should be granted immediately with an email notification. After that, the model page will show 

> Gated model: You have been granted access to this model

Create conda environment with pip and Python 3.12
```bash
conda create -n transformers_gemma pip python=3.12
conda activate transformers_gemma
```

Install [HuggingFace Transformers for Gemma 3](https://github.com/huggingface/transformers/releases/tag/v4.49.0-Gemma-3):
```bash
pip install git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3
```

Install [PyTorch](https://pytorch.org/get-started/locally/)

On Nvidia GPU (with CUDA 12.6):
```bash
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
```

On CPU:
```bash
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
```

Create an User Access Token from <https://huggingface.co/docs/hub/security-tokens>, then log in to your HuggingFace account with `huggingface-cli`:

```bash
huggingface-cli login
```

Copy-paste your access token and press enter.

## Packing

See <https://github.com/whitphx/gradio-pyinstaller-example> for more details

Create a hook file `runtime_hook.py` including environment variables

```python
# This is the hook patching the `multiprocessing.freeze_support` function,
# which we must import before calling `multiprocessing.freeze_support`.
import PyInstaller.hooks.rthooks.pyi_rth_multiprocessing  # noqa: F401
import os

if __name__ == "__main__":
    os.environ['PYINSTALLER'] = "1"
    os.environ['HF_ENDPOINT'] = "https://hf-mirror.com" # optional, HF mirror site in China
    os.environ['HF_TOKEN'] = "hf_XXXX"  # HF token that allow access to Gemma 3
    # This is necessary to prevent an infinite app launch loop.
    import multiprocessing
    multiprocessing.freeze_support()
```

Then

```commandline
pyi-makespec --collect-data=gradio_client --collect-data=gradio --collect-data=safehttpx --collect-data=groovy --runtime-hook=./runtime_hook.py app.py
```

open `app.spec` and add
```python
a = Analysis(
    ...,
    module_collection_mode={
        'gradio': 'py',  # Collect gradio package as source .py files
    }
}
```
then pack the environment
```commandline
pyinstaller --clean app.spec
```
finally copy the `win32ctypes` folder from your conda environment
```commandline
C:\Users\[Your-User-Name]\miniconda3\envs\[Your-Env-Name]\Lib\site-packages
```
to `dist/app/_internal`.

Run `app.exe` in `dist/app` and it should work.