Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
# 加载模型和tokenizer | |
model_name = "StevenChen16/llama3-8b-Lawyer" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
def generate_response(input_text): | |
inputs = tokenizer(input_text, return_tensors="pt") | |
outputs = model.generate(**inputs) | |
response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return response | |
# 创建 Gradio 接口 | |
iface = gr.Interface( | |
fn=generate_response, | |
inputs="text", | |
outputs="text", | |
title="Legal Assistant", | |
description="Enter your legal question and get a response from the model.", | |
) | |
# 运行应用 | |
if __name__ == "__main__": | |
iface.launch() | |