Spaces:
Sleeping
Sleeping
import gradio as gr | |
from huggingface_hub import InferenceClient | |
# Initialize the Hugging Face Inference Client | |
client = InferenceClient() | |
# Function to interact with the Qwen2.5-32B model and analyze code for compliance | |
def analyze_compliance(code, compliance_standard): | |
prompt = f"Analyze the following code for {compliance_standard} compliance and suggest modifications or refactoring to meet the guidelines:\n\n{code}" | |
messages = [ | |
{"role": "user", "content": prompt} | |
] | |
# Create a stream to receive generated content | |
stream = client.chat.completions.create( | |
model="Qwen/Qwen2.5-Coder-32B-Instruct", | |
messages=messages, | |
temperature=0.5, | |
max_tokens=1024, | |
top_p=0.7, | |
stream=True | |
) | |
# Collect the output from the stream | |
compliance_suggestions = "" | |
for chunk in stream: | |
compliance_suggestions += chunk.choices[0].delta.content | |
return compliance_suggestions | |
# Create Gradio interface | |
with gr.Blocks() as app: | |
gr.Markdown("## Legal and Compliance Code Advisor") | |
gr.Markdown("Analyze your code for legal compliance standards (e.g., GDPR, HIPAA) and receive modification suggestions.") | |
with gr.Row(): | |
code_input = gr.Textbox(lines=10, label="Code Snippet", placeholder="Enter your code here") | |
compliance_standard = gr.Dropdown( | |
choices=["GDPR", "HIPAA", "PCI-DSS", "SOC 2", "ISO 27001"], | |
label="Compliance Standard", | |
value="GDPR" | |
) | |
output_text = gr.Textbox(label="Compliance Suggestions", placeholder="Compliance suggestions will appear here...") | |
analyze_button = gr.Button("Analyze Compliance") | |
analyze_button.click(fn=analyze_compliance, inputs=[code_input, compliance_standard], outputs=output_text) | |
# Run the Gradio app | |
app.launch() | |