Pectics commited on
Commit
176b3fe
·
verified ·
1 Parent(s): f4c5a9b

Update API_KEY validator

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from spaces import GPU
2
 
 
3
  from threading import Thread
4
  from transformers import Qwen2VLForConditionalGeneration, Qwen2VLProcessor, TextIteratorStreamer, AutoProcessor, BatchFeature
5
  from qwen_vl_utils import process_vision_info
@@ -48,10 +49,13 @@ def infer(
48
  def respond(
49
  message,
50
  history,
 
51
  max_tokens,
52
  temperature,
53
  top_p,
54
  ):
 
 
55
  if len(history) == 0 or history[0]['role'] != 'system':
56
  messages = [{"role": "system", "content": """You are Softie, or 小软 in Chinese.
57
  You are an intelligent assistant developed by the School of Software at Hefei University of Technology.
@@ -68,6 +72,7 @@ app = ChatInterface(
68
  respond,
69
  type="messages",
70
  additional_inputs=[
 
71
  Slider(minimum=1, maximum=2048, value=512, step=1, label="最大生成长度"),
72
  Slider(minimum=0.01, maximum=4.0, value=0.75, step=0.01, label="温度系数(Temperature)"),
73
  Slider(minimum=0.01, maximum=1.0, value=0.5, step=0.01, label="核取样系数(Top-p)"),
 
1
  from spaces import GPU
2
 
3
+ from os import getenv
4
  from threading import Thread
5
  from transformers import Qwen2VLForConditionalGeneration, Qwen2VLProcessor, TextIteratorStreamer, AutoProcessor, BatchFeature
6
  from qwen_vl_utils import process_vision_info
 
49
  def respond(
50
  message,
51
  history,
52
+ api_key,
53
  max_tokens,
54
  temperature,
55
  top_p,
56
  ):
57
+ if api_key != getenv("API_KEY"):
58
+ raise ValueError("Invalid API Key")
59
  if len(history) == 0 or history[0]['role'] != 'system':
60
  messages = [{"role": "system", "content": """You are Softie, or 小软 in Chinese.
61
  You are an intelligent assistant developed by the School of Software at Hefei University of Technology.
 
72
  respond,
73
  type="messages",
74
  additional_inputs=[
75
+ Textbox(label="API Key"),
76
  Slider(minimum=1, maximum=2048, value=512, step=1, label="最大生成长度"),
77
  Slider(minimum=0.01, maximum=4.0, value=0.75, step=0.01, label="温度系数(Temperature)"),
78
  Slider(minimum=0.01, maximum=1.0, value=0.5, step=0.01, label="核取样系数(Top-p)"),