Zaid commited on
Commit
665015d
·
verified ·
1 Parent(s): f073a1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -14,12 +14,13 @@ MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
14
  model = None
15
  tokenizer = None
16
 
17
- def load_model():
18
- global model, tokenizer
19
- model_id = "stabilityai/ar-stablelm-2-chat"
20
- model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True)
21
- tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
22
- model.generation_config.pad_token_id = model.generation_config.eos_token_id
 
23
 
24
 
25
 
@@ -108,26 +109,27 @@ chat_interface = gr.ChatInterface(
108
  stop_btn=None,
109
  examples=[
110
  ["السلام عليكم"],
111
- ["اعرب الجملة التالية: ذهبت الى السوق"]
 
 
112
  ],
113
  cache_examples=False,
114
  type="messages",
115
  )
116
 
117
  with gr.Blocks(css_paths="style.css", fill_height=True) as demo:
118
- def authenticate_token(token):
119
- try:
120
- login(token = token)
121
- load_model()
122
- return "Authenticated successfully"
123
- except:
124
- return "Invalid token. Please try again."
125
 
126
- # Components
127
- token_input = gr.Textbox(label="Hugging Face Access Token", type="password", placeholder="Enter your token here...")
128
- auth_button = gr.Button("Authenticate")
129
- output = gr.Textbox(label="Output")
130
- auth_button.click(fn=authenticate_token, inputs=token_input, outputs=output)
131
  chat_interface.render()
132
 
133
 
 
14
  model = None
15
  tokenizer = None
16
 
17
+ my_token = os.getenv("HF_AUTH_TOKEN")
18
+ login(token = my_token)
19
+
20
+ model_id = "stabilityai/ar-stablelm-2-chat"
21
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True)
22
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
23
+ model.generation_config.pad_token_id = model.generation_config.eos_token_id
24
 
25
 
26
 
 
109
  stop_btn=None,
110
  examples=[
111
  ["السلام عليكم"],
112
+ ["اعرب الجملة التالية: ذهبت الى السوق"],
113
+ ["اضف تشكيل للجملة التالية: ضرب زيدا عمر"]،
114
+ ["كم عدد بحور الشعر العربي؟"]
115
  ],
116
  cache_examples=False,
117
  type="messages",
118
  )
119
 
120
  with gr.Blocks(css_paths="style.css", fill_height=True) as demo:
121
+ # def authenticate_token(token):
122
+ # try:
123
+ # login(token)
124
+ # return "Authenticated successfully"
125
+ # except:
126
+ # return "Invalid token. Please try again."
 
127
 
128
+ # # Components
129
+ # token_input = gr.Textbox(label="Hugging Face Access Token", type="password", placeholder="Enter your token here...")
130
+ # auth_button = gr.Button("Authenticate")
131
+ # output = gr.Textbox(label="Output")
132
+ # auth_button.click(fn=authenticate_token, inputs=token_input, outputs=output)
133
  chat_interface.render()
134
 
135