Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceApi
|
3 |
+
|
4 |
+
# 初始化 Inference API 客戶端
|
5 |
+
model_id = "dingckc/FineLlama-3.1-8B"
|
6 |
+
api_token = "hf_rhrXnUPYwsSCgmhidDnEXNXOkELWHLTr"
|
7 |
+
inference = InferenceApi(repo_id=model_id, token=api_token, task="text-generation")
|
8 |
+
|
9 |
+
# 定義推理函數
|
10 |
+
def evaluate_essay(title, essay):
|
11 |
+
input_text = f"""
|
12 |
+
Essay Title: {title}
|
13 |
+
Essay Rubric: Evaluate the argument based on clarity, coherence, lexical resource, and grammatical accuracy.
|
14 |
+
Essay: {essay}
|
15 |
+
Please generate a detailed evaluation based on the rubric provided above.
|
16 |
+
"""
|
17 |
+
response = inference(inputs=input_text)
|
18 |
+
return response.get("generated_text", "No evaluation available.")
|
19 |
+
|
20 |
+
# 使用 Gradio 構建界面
|
21 |
+
title_input = gr.inputs.Textbox(label="Essay Title")
|
22 |
+
essay_input = gr.inputs.Textbox(label="Essay Content", lines=10)
|
23 |
+
output_text = gr.outputs.Textbox(label="Evaluation Result")
|
24 |
+
|
25 |
+
gr.Interface(
|
26 |
+
fn=evaluate_essay,
|
27 |
+
inputs=[title_input, essay_input],
|
28 |
+
outputs=output_text,
|
29 |
+
title="Essay Evaluation",
|
30 |
+
description="Enter the title and content of your essay to receive an evaluation."
|
31 |
+
).launch()
|