File size: 3,673 Bytes
d66475a
 
 
 
 
 
312f855
 
d66475a
312f855
d66475a
312f855
 
d66475a
 
312f855
d66475a
312f855
 
 
 
 
 
 
 
 
 
 
 
d66475a
 
 
312f855
d66475a
 
 
 
 
 
 
 
312f855
d66475a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312f855
d66475a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
os.system('pip install transformers')
os.system('pip install gradio')
os.system('pip install requests')

import requests
import gradio as gr
from huggingface_hub import InferenceClient
from transformers import pipeline

# Inference client for chat completion
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")

# Different pipelines for different tasks
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")

def respond(message, system_message, max_tokens, temperature, top_p):
    messages = [{"role": "system", "content": system_message}]
    messages.append({"role": "user", "content": message})

    response = ""
    for message in client.chat_completion(
        messages,
        max_tokens=max_tokens,
        stream=True,
        temperature=temperature,
        top_p=top_p,
    ):
        token = message.choices[0].delta.content
        if token is not None:
            response += token
    return response

def generate_defense_argument(case_details):
    system_message = (
        "You are an expert Defense Attorney. Provide the best and most detailed arguments "
        "to defend the case based on the given case details. Include thorough analysis, "
        "evidence presentation, and any relevant legal precedents."
    )
    arguments = respond(case_details, system_message, max_tokens=1024, temperature=0.7, top_p=0.95)
    return arguments

# Custom CSS for a clean layout
custom_css = """
body {
    background-color: #ffffff;
    color: #000000;
    font-family: Arial, sans-serif;
}
.gradio-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.gr-button {
    background-color: #ffffff !important;
    border-color: #ffffff !important;
    color: #000000 !important;
    margin: 5px;
}
.gr-button:hover {
    background-color: #ffffff !important;
    border-color: #004085 !important;
}
.gr-input, .gr-textbox, .gr-slider, .gr-markdown, .gr-chatbox {
    border-radius: 4px;
    border: 1px solid #ced4da;
    background-color: #ffffff !important;
    color: #000000 !important;
}
.gr-input:focus, .gr-textbox:focus, .gr-slider:focus {
    border-color: #ffffff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 1.0);
}
#flagging-button {
    display: none;
}
footer {
    display: none;
}
.chatbox .chat-container .chat-message {
    background-color: #ffffff !important;
    color: #000000 !important;
}
.chatbox .chat-container .chat-message-input {
    background-color: #ffffff !important;
    color: #000000 !important;
}
.gr-markdown {
    background-color: #ffffff !important;
    color: #000000 !important;
}
.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 {
    color: #000000 !important;
}
.score-box {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center
}
"""

# Gradio Interface
with gr.Blocks(css=custom_css) as demo:
    with gr.Column():
        gr.Markdown("# Defense Expert\n### Provide Case Details")
        case_details = gr.Textbox(lines=5, placeholder="Enter case details here...")
        defense_argument = gr.Textbox(lines=10, placeholder="Defense's Argument...")
        
        generate_btn = gr.Button("Generate Argument")
        generate_btn.click(generate_defense_argument, inputs=[case_details], outputs=[defense_argument])
        
        clear_btn = gr.Button("Clear")
        clear_btn.click(lambda: "", None, defense_argument)

demo.launch()