GarGerry commited on
Commit
f065c86
·
verified ·
1 Parent(s): 8e00b9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,22 +1,22 @@
1
- import transformers
 
2
  import torch
3
 
4
- model_id = "meta-llama/Llama-3.3-70B-Instruct"
 
 
 
5
 
6
- pipeline = transformers.pipeline(
7
- "text-generation",
8
- model=model_id,
9
- model_kwargs={"torch_dtype": torch.bfloat16},
10
- device_map="auto",
11
- )
 
 
 
12
 
13
- messages = [
14
- {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
15
- {"role": "user", "content": "Who are you?"},
16
- ]
17
-
18
- outputs = pipeline(
19
- messages,
20
- max_new_tokens=256,
21
- )
22
- print(outputs[0]["generated_text"][-1])
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
 
5
+ # Load Model dan Tokenizer
6
+ model_name = "meta-llama/Llama-3.3-70B-Instruct"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
9
 
10
+ # Fungsi Chatbot
11
+ def chat(input_text):
12
+ # Tokenisasi input
13
+ inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
14
+ # Hasilkan output menggunakan model
15
+ outputs = model.generate(**inputs, max_length=1000, top_p=0.9, temperature=0.7)
16
+ # Decode output menjadi teks
17
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+ return response
19
 
20
+ # Membuat antarmuka Gradio
21
+ iface = gr.Interface(fn=chat, inputs="text", outputs="text", live=True)
22
+ iface.launch()