Spaces:
Running
Running
Update app.py
#1
by
Sg-at-srijan-us-kg
- opened
app.py
CHANGED
@@ -2,10 +2,13 @@ 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 stream the compliance suggestions as they are generated
|
8 |
-
def analyze_compliance_stream(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 = [
|
@@ -14,10 +17,9 @@ def analyze_compliance_stream(code, compliance_standard):
|
|
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=
|
21 |
top_p=0.7,
|
22 |
stream=True
|
23 |
)
|
@@ -28,10 +30,18 @@ def analyze_compliance_stream(code, compliance_standard):
|
|
28 |
compliance_suggestions += chunk.choices[0].delta.content
|
29 |
yield compliance_suggestions # Yield incremental content to display immediately
|
30 |
|
|
|
|
|
|
|
31 |
# Create Gradio interface with the modified layout
|
32 |
with gr.Blocks() as app:
|
33 |
gr.Markdown("## Code Compliance Advisor")
|
34 |
gr.Markdown("Analyze your code for legal compliance and security standards (e.g., GDPR, HIPAA) and receive actionable suggestions.")
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
with gr.Row():
|
37 |
# First column for input components
|
@@ -42,6 +52,7 @@ with gr.Blocks() as app:
|
|
42 |
label="Compliance Standard",
|
43 |
value="GDPR"
|
44 |
)
|
|
|
45 |
analyze_button = gr.Button("Analyze Compliance")
|
46 |
|
47 |
# Second column for output
|
@@ -50,7 +61,7 @@ with gr.Blocks() as app:
|
|
50 |
output_markdown = gr.Markdown()
|
51 |
|
52 |
# Link button to function with inputs and outputs
|
53 |
-
analyze_button.click(fn=analyze_compliance_stream, inputs=[code_input, compliance_standard], outputs=output_markdown)
|
54 |
|
55 |
# Run the Gradio app
|
56 |
app.launch()
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
# Initialize the Hugging Face Inference Client
|
5 |
+
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
|
6 |
|
7 |
# Function to stream the compliance suggestions as they are generated
|
8 |
+
def analyze_compliance_stream(code, compliance_standard, consent):
|
9 |
+
if not consent:
|
10 |
+
return "You must consent to the processing of your code snippet."
|
11 |
+
|
12 |
prompt = f"Analyze the following code for {compliance_standard} compliance and suggest modifications or refactoring to meet the guidelines:\n\n{code}"
|
13 |
|
14 |
messages = [
|
|
|
17 |
|
18 |
# Create a stream to receive generated content
|
19 |
stream = client.chat.completions.create(
|
|
|
20 |
messages=messages,
|
21 |
temperature=0.5,
|
22 |
+
max_tokens=32000,
|
23 |
top_p=0.7,
|
24 |
stream=True
|
25 |
)
|
|
|
30 |
compliance_suggestions += chunk.choices[0].delta.content
|
31 |
yield compliance_suggestions # Yield incremental content to display immediately
|
32 |
|
33 |
+
# Delete the code snippet after processing
|
34 |
+
del code
|
35 |
+
|
36 |
# Create Gradio interface with the modified layout
|
37 |
with gr.Blocks() as app:
|
38 |
gr.Markdown("## Code Compliance Advisor")
|
39 |
gr.Markdown("Analyze your code for legal compliance and security standards (e.g., GDPR, HIPAA) and receive actionable suggestions.")
|
40 |
+
gr.Markdown("### Privacy Notice")
|
41 |
+
gr.Markdown("""
|
42 |
+
By using this tool, you consent to the processing of your code snippet for compliance analysis. Your code will be sent to a third-party model for analysis and the results will be displayed to you. We do not store your code or the results unless required by law.
|
43 |
+
You have the right to access and erase your data. If you wish to request access to your data or have it erased, please contact us at [contact@example.com].
|
44 |
+
""")
|
45 |
|
46 |
with gr.Row():
|
47 |
# First column for input components
|
|
|
52 |
label="Compliance Standard",
|
53 |
value="GDPR"
|
54 |
)
|
55 |
+
consent_checkbox = gr.Checkbox(label="I consent to the processing of my code snippet", value=False)
|
56 |
analyze_button = gr.Button("Analyze Compliance")
|
57 |
|
58 |
# Second column for output
|
|
|
61 |
output_markdown = gr.Markdown()
|
62 |
|
63 |
# Link button to function with inputs and outputs
|
64 |
+
analyze_button.click(fn=analyze_compliance_stream, inputs=[code_input, compliance_standard, consent_checkbox], outputs=output_markdown)
|
65 |
|
66 |
# Run the Gradio app
|
67 |
app.launch()
|