snowkylin commited on
Commit
1c4a5e2
·
1 Parent(s): f1357f5

import transformers and pytorch only when needed

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -1,10 +1,5 @@
1
  import gradio as gr
2
  from gradio_i18n import Translate, gettext as _
3
- from transformers import AutoProcessor, Gemma3ForConditionalGeneration, TextIteratorStreamer
4
- import torch
5
- from threading import Thread
6
- import requests
7
- import json
8
  import io
9
  from PIL import Image
10
  import os
@@ -21,6 +16,9 @@ huggingface_spaces = "HUGGINGFACE_SPACES" in os.environ and os.environ['HUGGINGF
21
  local = "local" in os.environ and os.environ['LOCAL'] == "1"
22
 
23
  if huggingface_spaces or local:
 
 
 
24
  model = Gemma3ForConditionalGeneration.from_pretrained(
25
  model_id, device_map="auto"
26
  ).eval()
@@ -51,8 +49,7 @@ lang_store = {
51
  "description_placeholder": "Information that is not shown in the reference sheet, such as the character's name, personality, past stories and habit of saying.",
52
  "more_imgs": "More reference images of the character (optional)",
53
  "title": """# RefSheet Chat -- Chat with a character via reference sheet!""",
54
- "powered_by_gemma": "<p>Powered by <a href='https://blog.google/technology/developers/gemma-3/'>Gemma 3</a></p>",
55
- "upload": "Upload the reference sheet of your character here",
56
  "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.",
57
  "additional_info_prompt": "Additional info: ",
58
  "additional_reference_images_prompt": "Additional reference images of the character:",
@@ -76,6 +73,7 @@ lang_store = {
76
  "ru": "Russian",
77
  "ar": "Arabic",
78
  "default_language": "en",
 
79
  },
80
  "zh": {
81
  "confirm": "确认",
@@ -84,7 +82,6 @@ lang_store = {
84
  "description_placeholder": "未在设定图中包含的角色信息,如角色姓名、性格、言语习惯、过往经历等。",
85
  "more_imgs": "更多角色参考图(可选,可上传多张)",
86
  "title": """# RefSheet Chat——与设定图中的角色聊天!""",
87
- "powered_by_gemma": "<p>由 <a href='https://blog.google/technology/developers/gemma-3/'>Gemma 3</a> 驱动</p>",
88
  "upload": "在这里上传角色设定图",
89
  "prompt": "你的身份是图中的角色,使用%s。使用聊天的,口语化的方式表达。不在回复中直接提及参考图。无需确认。",
90
  "additional_info_prompt": "补充信息:",
@@ -109,6 +106,7 @@ lang_store = {
109
  "ru": "俄语",
110
  "ar": "阿拉伯语",
111
  "default_language": "zh",
 
112
  },
113
  }
114
 
@@ -292,6 +290,7 @@ with gr.Blocks(title="Chat with a character via reference sheet!") as demo:
292
  confirm_btn.click(prefill_chatbot, [img, description, more_imgs, character_language, engine, base_url, api_model, api_key], chat.chatbot)\
293
  .then(lambda x: x, chat.chatbot, chat.chatbot_value)
294
  gr.HTML(analytics_code)
 
295
  demo.load(set_default_character_language, None, character_language)
296
 
297
 
 
1
  import gradio as gr
2
  from gradio_i18n import Translate, gettext as _
 
 
 
 
 
3
  import io
4
  from PIL import Image
5
  import os
 
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
22
  model = Gemma3ForConditionalGeneration.from_pretrained(
23
  model_id, device_map="auto"
24
  ).eval()
 
49
  "description_placeholder": "Information that is not shown in the reference sheet, such as the character's name, personality, past stories and habit of saying.",
50
  "more_imgs": "More reference images of the character (optional)",
51
  "title": """# RefSheet Chat -- Chat with a character via reference sheet!""",
52
+ "upload": "Upload the reference sheet of the character here",
 
53
  "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.",
54
  "additional_info_prompt": "Additional info: ",
55
  "additional_reference_images_prompt": "Additional reference images of the character:",
 
73
  "ru": "Russian",
74
  "ar": "Arabic",
75
  "default_language": "en",
76
+ "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></p>"
77
  },
78
  "zh": {
79
  "confirm": "确认",
 
82
  "description_placeholder": "未在设定图中包含的角色信息,如角色姓名、性格、言语习惯、过往经历等。",
83
  "more_imgs": "更多角色参考图(可选,可上传多张)",
84
  "title": """# RefSheet Chat——与设定图中的角色聊天!""",
 
85
  "upload": "在这里上传角色设定图",
86
  "prompt": "你的身份是图中的角色,使用%s。使用聊天的,口语化的方式表达。不在回复中直接提及参考图。无需确认。",
87
  "additional_info_prompt": "补充信息:",
 
106
  "ru": "俄语",
107
  "ar": "阿拉伯语",
108
  "default_language": "zh",
109
+ "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>"
110
  },
111
  }
112
 
 
290
  confirm_btn.click(prefill_chatbot, [img, description, more_imgs, character_language, engine, base_url, api_model, api_key], chat.chatbot)\
291
  .then(lambda x: x, chat.chatbot, chat.chatbot_value)
292
  gr.HTML(analytics_code)
293
+ gr.Markdown(_("author"))
294
  demo.load(set_default_character_language, None, character_language)
295
 
296