Spaces:
Running
on
Zero
Running
on
Zero
StevenChen16
commited on
Commit
•
ba9fb68
1
Parent(s):
4186089
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# 加载模型和tokenizer
|
5 |
+
model_name = "StevenChen16/llama3-8b-Lawyer"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def generate_response(input_text):
|
10 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
11 |
+
outputs = model.generate(**inputs)
|
12 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
return response
|
14 |
+
|
15 |
+
# 创建 Gradio 接口
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=generate_response,
|
18 |
+
inputs="text",
|
19 |
+
outputs="text",
|
20 |
+
title="Legal Assistant",
|
21 |
+
description="Enter your legal question and get a response from the model.",
|
22 |
+
)
|
23 |
+
|
24 |
+
# 运行应用
|
25 |
+
if __name__ == "__main__":
|
26 |
+
iface.launch()
|