X34o commited on
Commit
b788d04
·
verified ·
1 Parent(s): 860281a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -53
app.py CHANGED
@@ -1,62 +1,27 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
- import torch
4
 
5
- model_name = "DavidAU/Qwen3.5-4B-Claude-4.6-OS-Auto-Variable-HERETIC-UNCENSORED-THINKING"
 
6
 
7
- bnb_config = BitsAndBytesConfig(
8
- load_in_4bit=True,
9
- bnb_4bit_compute_dtype=torch.float16,
10
- bnb_4bit_use_double_quant=True,
11
- bnb_4bit_quant_type="nf4"
12
  )
13
 
14
- tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
15
- model = AutoModelForCausalLM.from_pretrained(
16
- model_name,
17
- quantization_config=bnb_config,
18
- device_map="auto",
19
- low_cpu_mem_usage=True,
20
- trust_remote_code=True
21
- )
22
- model.eval()
23
-
24
- def generate_code(prompt):
25
- formatted = f"### Instruction:\n{prompt}\n### Response:\n"
26
-
27
- inputs = tokenizer(
28
- formatted,
29
- return_tensors="pt",
30
- truncation=True,
31
- max_length=1024
32
  )
33
-
34
- input_ids = inputs["input_ids"].to(model.device)
35
- attention_mask = inputs["attention_mask"].to(model.device)
36
-
37
- with torch.no_grad():
38
- output = model.generate(
39
- input_ids=input_ids,
40
- attention_mask=attention_mask,
41
- max_new_tokens=512,
42
- do_sample=True,
43
- temperature=0.7,
44
- pad_token_id=tokenizer.eos_token_id,
45
- eos_token_id=tokenizer.eos_token_id
46
- )
47
-
48
- new_tokens = output[0][input_ids.shape[-1]:]
49
- result = tokenizer.decode(new_tokens, skip_special_tokens=True)
50
- return result.strip()
51
 
52
  gr.Interface(
53
- fn=generate_code,
54
- inputs=gr.Textbox(
55
- lines=4,
56
- label="Request kode kamu",
57
- placeholder="Contoh: buatkan fungsi Python untuk REST API"
58
- ),
59
- outputs=gr.Code(label="Hasil kode", language="python"),
60
- title="Coding Assistant - Uncensored",
61
- description="Powered by Qwen3.5-4B Uncensored"
62
  ).launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
 
5
+ # Token dibaca dari secret, bukan hardcode
6
+ token = os.environ.get("HF_TOKEN")
7
 
8
+ client = InferenceClient(
9
+ model="NousResearch/Hermes-3-Llama-3.1-8B",
10
+ token=token
 
 
11
  )
12
 
13
+ def generate(prompt):
14
+ response = client.chat_completion(
15
+ messages=[{"role": "user", "content": prompt}],
16
+ max_tokens=512,
17
+ temperature=0.7
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  )
19
+ return response.choices[0].message.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  gr.Interface(
22
+ fn=generate,
23
+ inputs=gr.Textbox(lines=4, label="Tanya apa saja"),
24
+ outputs=gr.Textbox(label="Jawaban"),
25
+ title="AI Assistant - Uncensored",
26
+ description="Powered by HF Inference API"
 
 
 
 
27
  ).launch()