Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
model_id = "dingckc/FineLlama-3.1-8B"
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
# 定義推理函數
|
| 11 |
def evaluate_essay(title, essay):
|
|
@@ -15,9 +17,10 @@ def evaluate_essay(title, essay):
|
|
| 15 |
Essay: {essay}
|
| 16 |
Please generate a detailed evaluation based on the rubric provided above.
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
# 使用 Gradio 構建界面
|
| 23 |
title_input = gr.Textbox(label="Essay Title")
|
|
@@ -30,4 +33,4 @@ gr.Interface(
|
|
| 30 |
outputs=output_text,
|
| 31 |
title="Essay Evaluation",
|
| 32 |
description="Enter the title and content of your essay to receive an evaluation."
|
| 33 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
# 設置模型 ID 和加載 Hugging Face API token
|
| 7 |
model_id = "dingckc/FineLlama-3.1-8B"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=os.getenv('ACCESS_KEY'))
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, use_auth_token=os.getenv('ACCESS_KEY'))
|
| 10 |
+
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
|
| 12 |
# 定義推理函數
|
| 13 |
def evaluate_essay(title, essay):
|
|
|
|
| 17 |
Essay: {essay}
|
| 18 |
Please generate a detailed evaluation based on the rubric provided above.
|
| 19 |
"""
|
| 20 |
+
inputs = tokenizer(input_text, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 21 |
+
with torch.no_grad():
|
| 22 |
+
outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=150)
|
| 23 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
|
| 25 |
# 使用 Gradio 構建界面
|
| 26 |
title_input = gr.Textbox(label="Essay Title")
|
|
|
|
| 33 |
outputs=output_text,
|
| 34 |
title="Essay Evaluation",
|
| 35 |
description="Enter the title and content of your essay to receive an evaluation."
|
| 36 |
+
).launch(share=True)
|