Spaces:
Sleeping
Sleeping
| 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() | |