derricka59 commited on
Commit
317d95a
·
verified ·
1 Parent(s): 6c6d5da

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -13
app.py CHANGED
@@ -1,13 +1,41 @@
1
- from transformers import AutoTokenizer, AutoModelForCausalLM
2
- import torch
3
-
4
- tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-33b-instruct", trust_remote_code=True)
5
- model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-33b-instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
6
-
7
- messages=[
8
- { 'role': 'user', 'content': "who are you?"}
9
- ]
10
- inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
11
- # tokenizer.eos_token_id is the id of <|EOT|> token
12
- outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
13
- print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi, HfFolder
2
+ from pathlib import Path
3
+
4
+ # --- Configuration ---
5
+ # Your Hugging Face username
6
+ hf_username = "your-hf-username"
7
+ # The name of the new repository
8
+ repo_name = "deepseek-chatbot"
9
+ # The local path to your app.py file
10
+ local_app_py_path = "app.py"
11
+ # The path where the file should be in the repository
12
+ repo_app_py_path = "app.py"
13
+ # Your Hugging Face API token (replace with your actual token)
14
+ hf_token = "your-hf-token"
15
+
16
+ # --- Script ---
17
+ api = HfApi()
18
+ repo_id = f"{hf_username}/{repo_name}"
19
+
20
+ # Create the repository if it doesn't exist
21
+ try:
22
+ api.create_repo(repo_id=repo_id, token=hf_token, repo_type="space", space_sdk="docker")
23
+ print(f"Repository '{repo_id}' created on Hugging Face Hub.")
24
+ except Exception as e:
25
+ print(f"Repository '{repo_id}' may already exist: {e}")
26
+
27
+ # Read the content of the app.py file
28
+ app_py_content = Path(local_app_py_path).read_text()
29
+
30
+ # Commit the app.py file to the repository
31
+ try:
32
+ api.upload_file(
33
+ path_or_fileobj=app_py_content.encode("utf-8"),
34
+ path_in_repo=repo_app_py_path,
35
+ repo_id=repo_id,
36
+ token=hf_token,
37
+ commit_message="Add app.py for DeepSeek chatbot",
38
+ )
39
+ print(f"File '{repo_app_py_path}' committed to repository '{repo_id}'.")
40
+ except Exception as e:
41
+ print(f"Error committing file: {e}")