GarGerry commited on
Commit
60b8aa8
·
verified ·
1 Parent(s): 9a7bebe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -1,23 +1,21 @@
1
- from huggingface_hub import InferenceClient
2
- import os
3
 
4
- # Ambil token dari Repository secrets
5
- api_token = os.getenv("LLM")
 
6
 
7
- # Inisialisasi Inference Client
8
- client = InferenceClient(api_key=api_token)
 
 
 
 
 
 
9
 
10
- # Pesan dari user
11
- messages = [
12
- {"role": "user", "content": "What is the capital of France?"}
13
- ]
14
 
15
- # Inferensi menggunakan model
16
- completion = client.chat.completions.create(
17
- model="meta-llama/Llama-3.3-70B-Instruct",
18
- messages=messages,
19
- max_tokens=500
20
- )
21
-
22
- # Cetak jawaban dari model
23
- print(completion.choices[0].message)
 
1
+ import gradio as gr
2
+ from transformers import GPT2Tokenizer, GPT2Model
3
 
4
+ # Memuat tokenizer dan model GPT-2
5
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
6
+ model = GPT2Model.from_pretrained('gpt2')
7
 
8
+ # Fungsi untuk ekstraksi fitur dari teks
9
+ def extract_features(text):
10
+ # Tokenisasi input
11
+ encoded_input = tokenizer(text, return_tensors='pt')
12
+ # Mendapatkan output (misalnya, hidden states)
13
+ output = model(**encoded_input)
14
+ # Menampilkan fitur yang diinginkan (misalnya, hidden states)
15
+ return output.last_hidden_state
16
 
17
+ # Membuat antarmuka Gradio untuk input dan output
18
+ interface = gr.Interface(fn=extract_features, inputs="text", outputs="text")
 
 
19
 
20
+ # Meluncurkan aplikasi
21
+ interface.launch()