Spaces:
Runtime error
Runtime error
StevenChen16
commited on
Commit
•
8d4febf
1
Parent(s):
42eb58d
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,7 @@
|
|
1 |
-
|
2 |
-
from flask_cors import CORS
|
3 |
from llamafactory.chat import ChatModel
|
4 |
from llamafactory.extras.misc import torch_gc
|
5 |
|
6 |
-
app = Flask(__name__)
|
7 |
-
CORS(app)
|
8 |
-
|
9 |
args = dict(
|
10 |
model_name_or_path="StevenChen16/llama3-8b-Lawyer",
|
11 |
template="llama3",
|
@@ -25,20 +21,24 @@ You are an advanced AI legal assistant trained to assist with a wide range of le
|
|
25 |
5. **Professional Tone**: Maintain a professional and respectful tone in all responses. Ensure that your advice is legally sound and adheres to ethical standards.
|
26 |
"""
|
27 |
|
28 |
-
|
29 |
-
def query_model():
|
30 |
-
user_input = request.json.get('prompt', '')
|
31 |
combined_query = background_prompt + user_input
|
32 |
messages = [{"role": "user", "content": combined_query}]
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
if __name__ == '__main__':
|
44 |
-
|
|
|
1 |
+
import gradio as gr
|
|
|
2 |
from llamafactory.chat import ChatModel
|
3 |
from llamafactory.extras.misc import torch_gc
|
4 |
|
|
|
|
|
|
|
5 |
args = dict(
|
6 |
model_name_or_path="StevenChen16/llama3-8b-Lawyer",
|
7 |
template="llama3",
|
|
|
21 |
5. **Professional Tone**: Maintain a professional and respectful tone in all responses. Ensure that your advice is legally sound and adheres to ethical standards.
|
22 |
"""
|
23 |
|
24 |
+
def query_model(user_input):
|
|
|
|
|
25 |
combined_query = background_prompt + user_input
|
26 |
messages = [{"role": "user", "content": combined_query}]
|
27 |
+
|
28 |
+
response = ""
|
29 |
+
for new_text in chat_model.stream_chat(messages):
|
30 |
+
response += new_text
|
31 |
+
|
32 |
+
return response
|
33 |
+
|
34 |
+
# Gradio interface
|
35 |
+
interface = gr.Interface(
|
36 |
+
fn=query_model,
|
37 |
+
inputs="text",
|
38 |
+
outputs="text",
|
39 |
+
title="Legal AI Assistant",
|
40 |
+
description="Ask me any legal question related to US and Canada law.",
|
41 |
+
)
|
42 |
|
43 |
if __name__ == '__main__':
|
44 |
+
interface.launch()
|