Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system('pip install transformers')
|
3 |
+
os.system('pip install gradio')
|
4 |
+
os.system('pip install requests')
|
5 |
+
|
6 |
+
import requests
|
7 |
+
import gradio as gr
|
8 |
+
from huggingface_hub import InferenceClient
|
9 |
+
from transformers import pipeline
|
10 |
+
|
11 |
+
# Inference client for chat completion
|
12 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
13 |
+
|
14 |
+
# Different pipelines for different tasks
|
15 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
16 |
+
|
17 |
+
def respond(message, system_message, max_tokens, temperature, top_p):
|
18 |
+
messages = [{"role": "system", "content": system_message}]
|
19 |
+
messages.append({"role": "user", "content": message})
|
20 |
+
|
21 |
+
response = ""
|
22 |
+
for message in client.chat_completion(
|
23 |
+
messages,
|
24 |
+
max_tokens=max_tokens,
|
25 |
+
stream=True,
|
26 |
+
temperature=temperature,
|
27 |
+
top_p=top_p,
|
28 |
+
):
|
29 |
+
token = message.choices[0].delta.content
|
30 |
+
if token is not None:
|
31 |
+
response += token
|
32 |
+
return response
|
33 |
+
|
34 |
+
def generate_prosecution_argument(case_details):
|
35 |
+
system_message = (
|
36 |
+
"You are an expert Prosecution Attorney. Provide the best and most detailed arguments "
|
37 |
+
"to prosecute the case based on the given case details. Include thorough analysis, "
|
38 |
+
"evidence presentation, and any relevant legal precedents."
|
39 |
+
)
|
40 |
+
arguments = respond(case_details, system_message, max_tokens=1024, temperature=0.7, top_p=0.95)
|
41 |
+
return arguments
|
42 |
+
|
43 |
+
def generate_defense_argument(prosecution_argument):
|
44 |
+
system_message = (
|
45 |
+
"You are an expert Defense Attorney. Provide the best and most detailed arguments "
|
46 |
+
"to defend the case based on the given case details. Include thorough analysis, "
|
47 |
+
"evidence presentation, and any relevant legal precedents."
|
48 |
+
)
|
49 |
+
arguments = respond(prosecution_argument, system_message, max_tokens=1024, temperature=0.7, top_p=0.95)
|
50 |
+
return arguments
|
51 |
+
|
52 |
+
# Custom CSS for a clean layout
|
53 |
+
custom_css = """
|
54 |
+
body {
|
55 |
+
background-color: #ffffff;
|
56 |
+
color: #000000;
|
57 |
+
font-family: Arial, sans-serif;
|
58 |
+
}
|
59 |
+
.gradio-container {
|
60 |
+
max-width: 1000px;
|
61 |
+
margin: 0 auto;
|
62 |
+
padding: 20px;
|
63 |
+
background-color: #ffffff;
|
64 |
+
border: 1px solid #e0e0e0;
|
65 |
+
border-radius: 8px;
|
66 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
67 |
+
}
|
68 |
+
.gr-button {
|
69 |
+
background-color: #ffffff !important;
|
70 |
+
border-color: #ffffff !important;
|
71 |
+
color: #000000 !important;
|
72 |
+
margin: 5px;
|
73 |
+
}
|
74 |
+
.gr-button:hover {
|
75 |
+
background-color: #ffffff !important;
|
76 |
+
border-color: #004085 !important;
|
77 |
+
}
|
78 |
+
.gr-input, .gr-textbox, .gr-slider, .gr-markdown, .gr-chatbox {
|
79 |
+
border-radius: 4px;
|
80 |
+
border: 1px solid #ced4da;
|
81 |
+
background-color: #ffffff !important;
|
82 |
+
color: #000000 !important;
|
83 |
+
}
|
84 |
+
.gr-input:focus, .gr-textbox:focus, .gr-slider:focus {
|
85 |
+
border-color: #ffffff;
|
86 |
+
outline: 0;
|
87 |
+
box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 1.0);
|
88 |
+
}
|
89 |
+
#flagging-button {
|
90 |
+
display: none;
|
91 |
+
}
|
92 |
+
footer {
|
93 |
+
display: none;
|
94 |
+
}
|
95 |
+
.chatbox .chat-container .chat-message {
|
96 |
+
background-color: #ffffff !important;
|
97 |
+
color: #000000 !important;
|
98 |
+
}
|
99 |
+
.chatbox .chat-container .chat-message-input {
|
100 |
+
background-color: #ffffff !important;
|
101 |
+
color: #000000 !important;
|
102 |
+
}
|
103 |
+
.gr-markdown {
|
104 |
+
background-color: #ffffff !important;
|
105 |
+
color: #000000 !important;
|
106 |
+
}
|
107 |
+
.gr-markdown h1, .gr-markdown h2, .gr-markdown h3, .gr-markdown h4, .gr-markdown h5, .gr-markdown h6, .gr-markdown p, .gr-markdown ul, .gr-markdown ol, .gr-markdown li {
|
108 |
+
color: #000000 !important;
|
109 |
+
}
|
110 |
+
.score-box {
|
111 |
+
width: 60px;
|
112 |
+
height: 60px;
|
113 |
+
display: flex;
|
114 |
+
align-items: center
|
115 |
+
}
|
116 |
+
"""
|
117 |
+
|
118 |
+
# Gradio Interface
|
119 |
+
with gr.Blocks(css=custom_css) as demo:
|
120 |
+
with gr.Column():
|
121 |
+
gr.Markdown("# Court Argument Simulation\n### Provide Initial Case Details")
|
122 |
+
case_details = gr.Textbox(lines=5, placeholder="Enter initial case details here...")
|
123 |
+
prosecution_argument = gr.Textbox(lines=10, placeholder="Prosecution's Argument...")
|
124 |
+
defense_argument = gr.Textbox(lines=10, placeholder="Defense's Argument...")
|
125 |
+
|
126 |
+
def run_simulation(case_details):
|
127 |
+
prosecution_arg = generate_prosecution_argument(case_details)
|
128 |
+
defense_arg = generate_defense_argument(prosecution_arg)
|
129 |
+
return prosecution_arg, defense_arg
|
130 |
+
|
131 |
+
simulate_btn = gr.Button("Start Argument Simulation")
|
132 |
+
simulate_btn.click(run_simulation, inputs=[case_details], outputs=[prosecution_argument, defense_argument])
|
133 |
+
|
134 |
+
clear_btn = gr.Button("Clear")
|
135 |
+
clear_btn.click(lambda: ("", "", ""), None, [case_details, prosecution_argument, defense_argument])
|
136 |
+
|
137 |
+
demo.launch()
|