Rahatara commited on
Commit
32f04bc
·
verified ·
1 Parent(s): a0b0e9f

Update genbiasapp.py

Browse files
Files changed (1) hide show
  1. genbiasapp.py +40 -21
genbiasapp.py CHANGED
@@ -1,8 +1,6 @@
1
  import os
2
  import google.generativeai as genai
3
  import gradio as gr
4
- from PIL import Image
5
- import moviepy.editor as mp
6
  from google.generativeai.types import HarmBlockThreshold, HarmCategory
7
 
8
  # Configure Google API Key and model
@@ -14,8 +12,8 @@ model = genai.GenerativeModel(MODEL_ID)
14
  example_model = genai.GenerativeModel(
15
  MODEL_ID,
16
  system_instruction=[
17
- "You are an advocate against gender-based violence.",
18
- "Analyze the content for signs of gender discrimination and provide actionable advice."
19
  ],
20
  )
21
 
@@ -36,36 +34,57 @@ safety_settings = {
36
  HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
37
  }
38
 
39
- # Function to analyze text
40
  def analyze_text(text):
41
  prompt = f"Analyze this text for any instances of gender-based discrimination and provide tips: {text}"
42
- contents=[prompt]
43
  response = example_model.generate_content(
44
- contents,
45
- generation_config=generation_config,
46
- safety_settings=safety_settings,)
 
47
  return response.text if response else "No response generated."
48
 
49
- # Example scenarios
50
- example_scenarios = [
51
- ("During a team meeting, whenever a female colleague tried to express her opinion, she was often interrupted or talked over by male colleagues."),
52
- ("The feedback given to female employees often focuses more on their demeanor and less on their actual accomplishments."),
53
- ("Male employees are more frequently considered for promotions and challenging projects, even when female employees have similar or superior qualifications."),
54
- ("During a hiring panel, female candidates were often asked about their personal life, family plans, and how they would balance home and work."),
55
- ("There are significant wage discrepancies between male and female employees who hold the same position and possess comparable experience."),
56
- ("Some male colleagues often make inappropriate jokes or comments about female employees' appearances and attire."),
57
- ]
 
 
 
 
 
 
 
 
 
 
58
 
59
  # Gradio interface setup
60
- with gr.Blocks() as app:
 
 
 
61
  with gr.Tab("Text Analysis"):
62
- text_input = gr.Textbox(label="Enter Text", placeholder="Type here...", lines=4)
63
  analyze_text_btn = gr.Button("Analyze Text")
64
  text_output = gr.Textbox(label="Analysis Output", lines=6)
 
 
 
 
 
 
 
65
  analyze_text_btn.click(
66
  fn=analyze_text,
67
  inputs=text_input,
68
  outputs=text_output
69
  )
70
-
71
  app.launch()
 
1
  import os
2
  import google.generativeai as genai
3
  import gradio as gr
 
 
4
  from google.generativeai.types import HarmBlockThreshold, HarmCategory
5
 
6
  # Configure Google API Key and model
 
12
  example_model = genai.GenerativeModel(
13
  MODEL_ID,
14
  system_instruction=[
15
+ "You are an advocate against gender-based violence.",
16
+ "Analyze the content for signs of gender discrimination and provide actionable advice."
17
  ],
18
  )
19
 
 
34
  HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
35
  }
36
 
37
+ # Function to analyze text with error handling
38
  def analyze_text(text):
39
  prompt = f"Analyze this text for any instances of gender-based discrimination and provide tips: {text}"
40
+ contents = [prompt]
41
  response = example_model.generate_content(
42
+ contents,
43
+ generation_config=generation_config,
44
+ safety_settings=safety_settings,
45
+ )
46
  return response.text if response else "No response generated."
47
 
48
+ # Custom CSS for branding and animation
49
+ css = """
50
+ body { font-family: 'Arial', sans-serif; background-color: #f0f0f0; }
51
+ h1 { color: #333; animation: fadeIn 2s; }
52
+ @keyframes fadeIn {
53
+ from { opacity: 0; }
54
+ to { opacity: 1; }
55
+ }
56
+ #logo { font-size: 48px; color: #5f4b8b; animation: slideIn 2s; }
57
+ @keyframes slideIn {
58
+ 0% { margin-left: -200px; }
59
+ 100% { margin-left: 0px; }
60
+ }
61
+ .button { background-color: #4CAF50; color: white; padding: 14px 20px; margin: 8px 0; border: none; cursor: pointer; width: 100%; }
62
+ .button:hover { opacity: 0.8; }
63
+ .textbox { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; box-sizing: border-box; }
64
+ """
65
+
66
+ example_scenarios= [["aa"], ["b"]]
67
 
68
  # Gradio interface setup
69
+ with gr.Blocks(css=css) as app:
70
+ gr.Markdown("<div id='logo'>J<span>ustEva</span></div>")
71
+ gr.Markdown("<h1 style='text-align: center; color: #5f4b8b;'>Gender Bias Analysis Platform</h1>")
72
+ gr.Markdown("<p style='text-align: center; font-size: 16px; color: #4a4a4a;'>Powered by AI to advocate against gender-based violence</p>")
73
  with gr.Tab("Text Analysis"):
74
+ text_input = gr.Textbox(label="Enter Text or Select an Example", placeholder="Type here or select an example...", lines=4)
75
  analyze_text_btn = gr.Button("Analyze Text")
76
  text_output = gr.Textbox(label="Analysis Output", lines=6)
77
+
78
+ examples = gr.Examples(
79
+ examples=example_scenarios,
80
+ inputs=text_input,
81
+ outputs=text_output
82
+ )
83
+
84
  analyze_text_btn.click(
85
  fn=analyze_text,
86
  inputs=text_input,
87
  outputs=text_output
88
  )
89
+
90
  app.launch()