testing-space / app.py
dingckc's picture
Create app.py
a2d6aac verified
raw
history blame
1.14 kB
import gradio as gr
from huggingface_hub import InferenceApi
# 初始化 Inference API 客戶端
model_id = "dingckc/FineLlama-3.1-8B"
api_token = "hf_rhrXnUPYwsSCgmhidDnEXNXOkELWHLTr"
inference = InferenceApi(repo_id=model_id, token=api_token, task="text-generation")
# 定義推理函數
def evaluate_essay(title, essay):
input_text = f"""
Essay Title: {title}
Essay Rubric: Evaluate the argument based on clarity, coherence, lexical resource, and grammatical accuracy.
Essay: {essay}
Please generate a detailed evaluation based on the rubric provided above.
"""
response = inference(inputs=input_text)
return response.get("generated_text", "No evaluation available.")
# 使用 Gradio 構建界面
title_input = gr.inputs.Textbox(label="Essay Title")
essay_input = gr.inputs.Textbox(label="Essay Content", lines=10)
output_text = gr.outputs.Textbox(label="Evaluation Result")
gr.Interface(
fn=evaluate_essay,
inputs=[title_input, essay_input],
outputs=output_text,
title="Essay Evaluation",
description="Enter the title and content of your essay to receive an evaluation."
).launch()