Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,22 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import torch
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
)
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|