phamvanla commited on
Commit
1d46114
·
1 Parent(s): 067e6e3

update output

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -1,6 +1,8 @@
1
- import gradio as gr
2
  import os
 
 
3
  from transformers import pipeline
 
4
 
5
  # Lấy token từ biến môi trường
6
  token = os.getenv("TOKEN")
@@ -9,19 +11,41 @@ if token is None:
9
  raise ValueError("TOKEN environment variable not set")
10
 
11
  # Đăng nhập vào Hugging Face bằng token
12
- from huggingface_hub import login
13
  login(token=token)
14
 
15
  # Tải mô hình từ Hugging Face Hub
16
  model_name = "HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1"
17
- classifier = pipeline("text-classification", model=model_name, token=token)
 
 
 
 
 
18
 
19
  # Định nghĩa hàm xử lý
20
- def classify_text(text):
21
- return classifier(text)
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Tạo interface Gradio
24
- iface = gr.Interface(fn=classify_text, inputs="text", outputs="label")
 
 
 
 
 
 
25
 
26
  # Khởi chạy ứng dụng
27
  iface.launch(share=True)
 
 
1
  import os
2
+ import gradio as gr
3
+ import torch
4
  from transformers import pipeline
5
+ from huggingface_hub import login
6
 
7
  # Lấy token từ biến môi trường
8
  token = os.getenv("TOKEN")
 
11
  raise ValueError("TOKEN environment variable not set")
12
 
13
  # Đăng nhập vào Hugging Face bằng token
 
14
  login(token=token)
15
 
16
  # Tải mô hình từ Hugging Face Hub
17
  model_name = "HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1"
18
+ pipe = pipeline(
19
+ "text-generation",
20
+ model=model_name,
21
+ device_map="auto",
22
+ torch_dtype=torch.bfloat16,
23
+ )
24
 
25
  # Định nghĩa hàm xử lý
26
+ def generate_text(user_input):
27
+ messages = [
28
+ {"role": "system", "content": "You are Zephyr, a helpful assistant."},
29
+ {"role": "user", "content": user_input},
30
+ ]
31
+ outputs = pipe(
32
+ messages,
33
+ max_new_tokens=512,
34
+ do_sample=True,
35
+ temperature=0.7,
36
+ top_k=50,
37
+ top_p=0.95,
38
+ )
39
+ return outputs[0]["generated_text"]
40
 
41
  # Tạo interface Gradio
42
+ iface = gr.Interface(
43
+ fn=generate_text,
44
+ inputs="text",
45
+ outputs="text",
46
+ title="Zephyr - Text Generation",
47
+ description="Generate text responses using the Zephyr model."
48
+ )
49
 
50
  # Khởi chạy ứng dụng
51
  iface.launch(share=True)