BorderCollieWei commited on
Commit
3e37a08
·
verified ·
1 Parent(s): 86c7c6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -1,18 +1,12 @@
1
  # -*- coding: utf-8 -*-
2
- """Hugging Face.ipynb
3
 
4
- Automatically generated by Colab.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1zRuAxGm_11lNIeBxFlHVzc5tNKhyLef4
8
- """
9
  import gradio as gr
10
- # 加載 LLaMA 模型
11
  from transformers import AutoTokenizer, AutoModelForCausalLM
12
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
13
 
14
- tokenizer = AutoTokenizer.from_pretrained("google/t5-v1_1-xxl")
15
- model = AutoModelForSeq2SeqLM.from_pretrained("google/t5-v1_1-xxl")
 
16
 
17
  # 定義推理函數
18
  def generate_text(prompt):
@@ -26,15 +20,15 @@ def generate_text(prompt):
26
  )
27
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
28
 
29
- # 使用 Gradio 构建界面
30
  interface = gr.Interface(
31
  fn=generate_text,
32
  inputs=gr.Textbox(lines=5, placeholder="Enter your prompt here..."),
33
  outputs="text",
34
- title="T5 Text Generator",
35
- description="Generate text using the T5 v1.1 XXL model hosted on Hugging Face Spaces."
36
  )
37
 
38
  # 啟動應用
39
  if __name__ == "__main__":
40
- interface.launch()
 
1
  # -*- coding: utf-8 -*-
2
+ """Hugging Face Llama 2 App"""
3
 
 
 
 
 
 
4
  import gradio as gr
 
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
6
 
7
+ # 加載 LLaMA-2 模型
8
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-13b-chat-hf")
9
+ model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-13b-chat-hf")
10
 
11
  # 定義推理函數
12
  def generate_text(prompt):
 
20
  )
21
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
22
 
23
+ # 使用 Gradio 構建界面
24
  interface = gr.Interface(
25
  fn=generate_text,
26
  inputs=gr.Textbox(lines=5, placeholder="Enter your prompt here..."),
27
  outputs="text",
28
+ title="Llama 2 Text Generator",
29
+ description="Generate text using the Llama-2-13b-chat-hf model hosted on Hugging Face Spaces."
30
  )
31
 
32
  # 啟動應用
33
  if __name__ == "__main__":
34
+ interface.launch()