yasserrmd commited on
Commit
a46abdf
·
verified ·
1 Parent(s): ed2b3c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
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 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 = [
@@ -22,29 +22,35 @@ def analyze_compliance(code, compliance_standard):
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()
 
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()