File size: 770 Bytes
ba9fb68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()