snowkylin commited on
Commit
35ba64f
·
1 Parent(s): df18092

update ui, add pyinstaller

Browse files
Files changed (2) hide show
  1. app.py +38 -16
  2. requirements.txt +1 -0
app.py CHANGED
@@ -6,16 +6,18 @@ import os
6
  import base64
7
  from openai import OpenAI
8
 
9
- default_img = None
10
- default_engine = "api"
11
- default_base_url = "https://openrouter.ai/api/v1"
12
- default_api_model = "google/gemma-3-27b-it"
13
 
14
- model_id = "google/gemma-3-4b-it"
15
  huggingface_spaces = "HUGGINGFACE_SPACES" in os.environ and os.environ['HUGGINGFACE_SPACES'] == "1"
16
  local = "LOCAL" in os.environ and os.environ['LOCAL'] == "1"
 
 
 
 
 
 
 
17
 
18
- if huggingface_spaces or local:
19
  from transformers import AutoProcessor, Gemma3ForConditionalGeneration, TextIteratorStreamer
20
  import torch
21
  from threading import Thread
@@ -54,13 +56,21 @@ lang_store = {
54
  <span style='float: right'><iframe src="https://ghbtns.com/github-btn.html?user=snowkylin&repo=refsheet_chat&type=star&count=true" frameborder="0" scrolling="0" width="80" height="20" title="GitHub"></span></iframe>
55
  </h1>
56
 
57
- Upload a [reference sheet](https://www.google.com/search?q=reference+sheet+art) of a character, then RefSheet Chat will try to understand the character through the reference sheet, and talk to you as that character.
58
 
59
- You can also add text descriptions and provide more reference pictures to help RefSheet Chat understand the character more accurately. The content you provide is only used for RefSheet Chat to understand the character and talk to you, and will not be used for other purposes. You can [run the program on your own computer](https://github.com/snowkylin/refsheet_chat) without Internet to ensure privacy.
 
 
 
 
 
 
 
 
60
 
61
  How will RefSheet Chat understand your character? Have a try!""",
62
  "upload": "Upload the reference sheet of the character here",
63
- "prompt": "You are the character in the image, use %s. Use a conversational, oral tone. Do not mention the reference images directly. Start without confirmation.",
64
  "additional_info_prompt": "Additional info: ",
65
  "additional_reference_images_prompt": "Additional reference images of the character:",
66
  "description": "Description",
@@ -83,7 +93,7 @@ How will RefSheet Chat understand your character? Have a try!""",
83
  "ru": "Russian",
84
  "ar": "Arabic",
85
  "default_language": "en",
86
- "author": "<p align='center'>Developed by <a href='https://github.com/snowkylin'>snowkylin</a>, powered by <a href='https://blog.google/technology/developers/gemma-3/'>Gemma 3</a> open model</p>"
87
  },
88
  "zh": {
89
  "confirm": "确认",
@@ -97,13 +107,21 @@ How will RefSheet Chat understand your character? Have a try!""",
97
  <span style='float: right'><iframe src="https://ghbtns.com/github-btn.html?user=snowkylin&repo=refsheet_chat&type=star&count=true" frameborder="0" scrolling="0" width="80" height="20" title="GitHub"></span></iframe>
98
  </h1>
99
 
100
- “一图胜千言”——上传一张[角色设定图](https://www.bing.com/images/search?q=%E8%A7%92%E8%89%B2%E8%AE%BE%E5%AE%9A%E5%9B%BE)(reference sheet),RefSheet Chat 即会理解和“脑补”设定图中的信息,并以这位角色的身份与您对话。
 
 
 
 
 
 
 
 
101
 
102
- 您也可以补充文字描述以及提供更多的参考图,以帮助 RefSheet Chat 更准确地理解角色。您提供的内容仅用于 RefSheet Chat 理解角色并与您对话,不会另做他用。您可以[在自己的电脑上离线运行该程序](https://github.com/snowkylin/refsheet_chat)以确保隐私。
103
 
104
  RefSheet Chat 将如何理解您的角色呢?试试看!""",
105
  "upload": "在这里上传角色设定图",
106
- "prompt": "你的身份是图中的角色,使用%s。使用聊天的,口语化的方式表达。不在回复中直接提及参考图。无需确认。",
107
  "additional_info_prompt": "补充信息:",
108
  "additional_reference_images_prompt": "该角色的更多参考图:",
109
  "description": "额外角色设定",
@@ -126,7 +144,7 @@ RefSheet Chat 将如何理解您的角色呢?试试看!""",
126
  "ru": "俄语",
127
  "ar": "阿拉伯语",
128
  "default_language": "zh",
129
- "author": """<p align='center'>由 <a href='https://github.com/snowkylin'>snowkylin</a> 开发,由开源的 <a href='https://blog.google/technology/developers/gemma-3/'>Gemma 3</a> 驱动</p>"""
130
  },
131
  }
132
 
@@ -228,7 +246,7 @@ def set_default_character_language(request: gr.Request):
228
 
229
  with gr.Blocks(title="Chat with a character via reference sheet!") as demo:
230
  with Translate(lang_store) as lang:
231
- gr.Markdown(_("title"), sanitize_html=False)
232
  img = gr.Image(type="filepath", value=default_img, label=_("upload"), render=False)
233
  description = gr.TextArea(
234
  value=_("default_description"),
@@ -313,4 +331,8 @@ with gr.Blocks(title="Chat with a character via reference sheet!") as demo:
313
 
314
 
315
  if __name__ == "__main__":
316
- demo.launch()
 
 
 
 
 
6
  import base64
7
  from openai import OpenAI
8
 
 
 
 
 
9
 
 
10
  huggingface_spaces = "HUGGINGFACE_SPACES" in os.environ and os.environ['HUGGINGFACE_SPACES'] == "1"
11
  local = "LOCAL" in os.environ and os.environ['LOCAL'] == "1"
12
+ pyinstaller = "PYINSTALLER" in os.environ and os.environ['PYINSTALLER'] == "1"
13
+
14
+ default_img = None
15
+ default_engine = "local" if pyinstaller else "api"
16
+ default_base_url = "https://openrouter.ai/api/v1"
17
+ default_api_model = "google/gemma-3-27b-it"
18
+ model_id = "models--google--gemma-3-4b-it/snapshots/dbd91bbaf64a0e591f4340ce8b66fd1dba9ab6bd" if pyinstaller else "google/gemma-3-4b-it"
19
 
20
+ if huggingface_spaces or local or pyinstaller:
21
  from transformers import AutoProcessor, Gemma3ForConditionalGeneration, TextIteratorStreamer
22
  import torch
23
  from threading import Thread
 
56
  <span style='float: right'><iframe src="https://ghbtns.com/github-btn.html?user=snowkylin&repo=refsheet_chat&type=star&count=true" frameborder="0" scrolling="0" width="80" height="20" title="GitHub"></span></iframe>
57
  </h1>
58
 
59
+ Upload a <a href="https://www.google.com/search?q=reference+sheet+art" target="_blank">reference sheet</a> of a character, then RefSheet Chat will try to understand the character through the reference sheet, and talk to you as that character.
60
 
61
+ You can also add text descriptions and provide more reference pictures to help RefSheet Chat understand the character more accurately. The content you provide is only used for RefSheet Chat to understand the character and talk to you, and will not be used for other purposes. You can [run the program on your own computer](https://refsheet.chat/local) without Internet to ensure privacy.
62
+
63
+ How will RefSheet Chat understand your character? Have a try!""",
64
+ "title_pyinstaller": """
65
+ <h1>RefSheet Chat -- Chat with a character via reference sheet!</h1>
66
+
67
+ Upload a <a href="https://www.google.com/search?q=reference+sheet+art" target="_blank">reference sheet</a> of a character, then RefSheet Chat will try to understand the character through the reference sheet, and talk to you as that character.
68
+
69
+ You can also add text descriptions and provide more reference pictures to help RefSheet Chat understand the character more accurately. The RefSheet Chat you are currently using is completely offline and does not upload any data to the Internet. If you want faster operation and better conversation quality, you can visit <a href="https://refsheet.chat" target="_blank">https://refsheet.chat</a> to use the online version.
70
 
71
  How will RefSheet Chat understand your character? Have a try!""",
72
  "upload": "Upload the reference sheet of the character here",
73
+ "prompt": "You are the character in the image, use %s. Use a conversational, oral tone. Do not mention the reference images. Start without confirmation.",
74
  "additional_info_prompt": "Additional info: ",
75
  "additional_reference_images_prompt": "Additional reference images of the character:",
76
  "description": "Description",
 
93
  "ru": "Russian",
94
  "ar": "Arabic",
95
  "default_language": "en",
96
+ "author": "<p align='center'><a href='https://github.com/snowkylin/refsheet_chat' target='_blank'>RefSheet Chat</a> is open-sourced, developed by <a href='https://github.com/snowkylin' target='_blank'>snowkylin</a>, and powered by <a href='https://blog.google/technology/developers/gemma-3/' target='_blank'>Gemma 3</a></p>"
97
  },
98
  "zh": {
99
  "confirm": "确认",
 
107
  <span style='float: right'><iframe src="https://ghbtns.com/github-btn.html?user=snowkylin&repo=refsheet_chat&type=star&count=true" frameborder="0" scrolling="0" width="80" height="20" title="GitHub"></span></iframe>
108
  </h1>
109
 
110
+ “一图胜千言”——提供一张<a href="https://www.bing.com/images/search?q=%E8%A7%92%E8%89%B2%E8%AE%BE%E5%AE%9A%E5%9B%BE" target="_blank">角色设定图</a>(reference sheet),RefSheet Chat 即会理解和“脑补”设定图中的信息,并以这位角色的身份与您对话。
111
+
112
+ 您也可以补充文字描述以及提供更多的参考图,以帮助 RefSheet Chat 更准确地理解角色。您提供的内容仅用于 RefSheet Chat 理解角色并与您对话,不会另做他用。您可以[在自己的电脑上离线运行该程序](https://refsheet.chat/local)以确保隐私。
113
+
114
+ RefSheet Chat 将如何理解您的角色呢?试试看!""",
115
+ "title_pyinstaller": """
116
+ <h1>RefSheet Chat——与设定图中的角色聊天!</h1>
117
+
118
+ “一图胜千言”——提供一张<a href="https://www.bing.com/images/search?q=%E8%A7%92%E8%89%B2%E8%AE%BE%E5%AE%9A%E5%9B%BE" target="_blank">角色设定图</a>(reference sheet),RefSheet Chat 即会理解和“脑补”设定图中的信息,并以这位角色的身份与您对话。
119
 
120
+ 您也可以补充文字描述以及提供更多的参考图,以帮助 RefSheet Chat 更准确地理解角色。您当前使用的 RefSheet Chat 是完全离线运行的,不会将任何数据上传到互联网。如果希望获得更快的运行速度和对话质量,可以访问 <a href="https://refsheet.chat" target="_blank">https://refsheet.chat</a> 使用线上版本。
121
 
122
  RefSheet Chat 将如何理解您的角色呢?试试看!""",
123
  "upload": "在这里上传角色设定图",
124
+ "prompt": "你的身份是图中的角色,使用%s。使用聊天的,口语化的方式表达。不在回复中提及参考图的存在。无需确认。",
125
  "additional_info_prompt": "补充信息:",
126
  "additional_reference_images_prompt": "该角色的更多参考图:",
127
  "description": "额外角色设定",
 
144
  "ru": "俄语",
145
  "ar": "阿拉伯语",
146
  "default_language": "zh",
147
+ "author": """<p align='center'><a href='https://github.com/snowkylin/refsheet_chat' target='_blank'>RefSheet Chat</a> 是开源的,由 <a href='https://github.com/snowkylin' target='_blank'>snowkylin</a> 开发,由开源的 <a href='https://blog.google/technology/developers/gemma-3/' target='_blank'>Gemma 3</a> 驱动</p>"""
148
  },
149
  }
150
 
 
246
 
247
  with gr.Blocks(title="Chat with a character via reference sheet!") as demo:
248
  with Translate(lang_store) as lang:
249
+ gr.Markdown(_("title_pyinstaller" if pyinstaller else "title"), sanitize_html=False)
250
  img = gr.Image(type="filepath", value=default_img, label=_("upload"), render=False)
251
  description = gr.TextArea(
252
  value=_("default_description"),
 
331
 
332
 
333
  if __name__ == "__main__":
334
+ demo.launch(prevent_thread_lock=True if pyinstaller else False)
335
+ if pyinstaller:
336
+ import webview
337
+ window = webview.create_window("RefSheet Chat", demo.local_url, maximized=True)
338
+ webview.start()
requirements.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  gradio
2
  gradio_i18n
3
  git+https://github.com/huggingface/[email protected]
 
1
+ --index-url=https://download.pytorch.org/whl/cpu --extra-index-url=https://pypi.org/simple
2
  gradio
3
  gradio_i18n
4
  git+https://github.com/huggingface/[email protected]