Spaces:
Runtime error
Runtime error
import gradio as gr | |
from huggingface_hub import InferenceClient | |
import os | |
# 初始化 Inference API 客戶端 | |
model_id = "dingckc/FineLlama-3.1-8B" | |
api_token = os.getenv('ACCESS_KEY') | |
inference = InferenceClient(model=model_id, token=api_token) | |
# 定義推理函數 | |
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. | |
""" | |
# 使用 text_generation 方法進行推理 | |
response = inference.text_generation(input_text) | |
return response[0]["generated_text"] if "generated_text" in response[0] else "No evaluation available." | |
# 使用 Gradio 構建界面 | |
title_input = gr.Textbox(label="Essay Title") | |
essay_input = gr.Textbox(label="Essay Content", lines=10) | |
output_text = gr.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() | |