Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,12 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
"""Hugging Face
|
| 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 |
-
|
| 15 |
-
|
|
|
|
| 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="
|
| 35 |
-
description="Generate text using the
|
| 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()
|