Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
# Initialize the Hugging Face Inference Client
|
5 |
+
client = InferenceClient()
|
6 |
+
|
7 |
+
# Function to interact with the Qwen2.5-32B model and analyze code for compliance
|
8 |
+
def analyze_compliance(code, compliance_standard):
|
9 |
+
prompt = f"Analyze the following code for {compliance_standard} compliance and suggest modifications or refactoring to meet the guidelines:\n\n{code}"
|
10 |
+
|
11 |
+
messages = [
|
12 |
+
{"role": "user", "content": prompt}
|
13 |
+
]
|
14 |
+
|
15 |
+
# Create a stream to receive generated content
|
16 |
+
stream = client.chat.completions.create(
|
17 |
+
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
18 |
+
messages=messages,
|
19 |
+
temperature=0.5,
|
20 |
+
max_tokens=1024,
|
21 |
+
top_p=0.7,
|
22 |
+
stream=True
|
23 |
+
)
|
24 |
+
|
25 |
+
# Collect the output from the stream
|
26 |
+
compliance_suggestions = ""
|
27 |
+
for chunk in stream:
|
28 |
+
compliance_suggestions += chunk.choices[0].delta.content
|
29 |
+
|
30 |
+
return compliance_suggestions
|
31 |
+
|
32 |
+
# Create Gradio interface
|
33 |
+
with gr.Blocks() as app:
|
34 |
+
gr.Markdown("## Legal and Compliance Code Advisor")
|
35 |
+
gr.Markdown("Analyze your code for legal compliance standards (e.g., GDPR, HIPAA) and receive modification suggestions.")
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
code_input = gr.Textbox(lines=10, label="Code Snippet", placeholder="Enter your code here")
|
39 |
+
compliance_standard = gr.Dropdown(
|
40 |
+
choices=["GDPR", "HIPAA", "PCI-DSS", "SOC 2", "ISO 27001"],
|
41 |
+
label="Compliance Standard",
|
42 |
+
value="GDPR"
|
43 |
+
)
|
44 |
+
output_text = gr.Textbox(label="Compliance Suggestions", placeholder="Compliance suggestions will appear here...")
|
45 |
+
|
46 |
+
analyze_button = gr.Button("Analyze Compliance")
|
47 |
+
analyze_button.click(fn=analyze_compliance, inputs=[code_input, compliance_standard], outputs=output_text)
|
48 |
+
|
49 |
+
# Run the Gradio app
|
50 |
+
app.launch()
|