Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,10 @@ 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
|
8 |
-
def
|
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 = [
|
@@ -22,29 +22,35 @@ def analyze_compliance(code, compliance_standard):
|
|
22 |
stream=True
|
23 |
)
|
24 |
|
25 |
-
#
|
26 |
compliance_suggestions = ""
|
27 |
for chunk in stream:
|
28 |
compliance_suggestions += chunk.choices[0].delta.content
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
# Create Gradio interface
|
33 |
with gr.Blocks() as app:
|
34 |
-
gr.Markdown("##
|
35 |
-
gr.Markdown("Analyze your code for legal compliance standards (e.g., GDPR, HIPAA) and receive
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
|
|
|
46 |
analyze_button = gr.Button("Analyze Compliance")
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
# Run the Gradio app
|
50 |
-
app.launch()
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
# Initialize the Hugging Face Inference Client
|
5 |
+
client = InferenceClient(api_key="YOUR_HF_TOKEN")
|
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 = [
|
|
|
22 |
stream=True
|
23 |
)
|
24 |
|
25 |
+
# Stream content as it is generated
|
26 |
compliance_suggestions = ""
|
27 |
for chunk in stream:
|
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 |
+
# Full-width text area for code input
|
37 |
+
code_input = gr.Textbox(lines=10, label="Code Snippet", placeholder="Enter your code here", elem_id="full_width")
|
38 |
+
|
39 |
+
# Dropdown for selecting compliance standard
|
40 |
+
compliance_standard = gr.Dropdown(
|
41 |
+
choices=["GDPR", "HIPAA", "PCI-DSS", "SOC 2", "ISO 27001"],
|
42 |
+
label="Compliance Standard",
|
43 |
+
value="GDPR"
|
44 |
+
)
|
45 |
|
46 |
+
# Button to trigger analysis
|
47 |
analyze_button = gr.Button("Analyze Compliance")
|
48 |
+
|
49 |
+
# Result display in Markdown to HTML
|
50 |
+
output_html = gr.HTML(label="Compliance Suggestions")
|
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_html, every=0.1)
|
54 |
|
55 |
# Run the Gradio app
|
56 |
+
app.launch()
|