Rahatara commited on
Commit
a756cb9
·
verified ·
1 Parent(s): 21ac5a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -11,7 +11,6 @@ genai.configure(api_key=GOOGLE_API_KEY)
11
  MODEL_ID = "gemini-1.5-pro-002"
12
  model = genai.GenerativeModel(MODEL_ID)
13
 
14
-
15
  example_model = genai.GenerativeModel(
16
  MODEL_ID,
17
  system_instruction=[
@@ -21,7 +20,7 @@ example_model = genai.GenerativeModel(
21
  )
22
 
23
  # Set model parameters
24
- generation_config =genai.GenerationConfig(
25
  temperature=0.9,
26
  top_p=1.0,
27
  top_k=32,
@@ -37,37 +36,37 @@ safety_settings = {
37
  HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
38
  }
39
 
40
- # Prompt the model to generate content
41
-
42
  # Function to analyze text
43
  def analyze_text(text):
44
- prompt = f"Analyze this text for any instances of gender-based discrimination and provide tips{text}"
45
  contents=[prompt]
46
  response = example_model.generate_content(
47
  contents,
48
  generation_config=generation_config,
49
  safety_settings=safety_settings,)
50
  return response.text if response else "No response generated."
51
- # Define example scenarios
 
52
  example_scenarios = [
53
- "During a team meeting, I noticed that whenever a female colleague tried to express her opinion, she was often interrupted or talked over by male colleagues. Her contributions were rarely acknowledged, whereas comments from male counterparts received immediate attention and discussion.",
54
- "In the performance reviews, it seems that the feedback given to female employees often focuses more on their demeanor and less on their actual accomplishments compared to their male colleagues. Terms like 'bossy' and 'emotional' are frequently used in the evaluations of women, unlike in the reviews for men.",
55
- "I have observed that male employees are more frequently considered for promotions and challenging projects, even when female employees have similar or superior qualifications. Discussions about career advancement opportunities with female staff often also include considerations about family life and children, which is not the case with male staff.",
56
- "During a hiring panel, I noticed a difference in how male and female candidates were questioned. Female candidates were often asked about their personal life, family plans, and how they would balance home and work. Such questions were not posed to male candidates.",
57
- "In informal discussions among employees, it was revealed that there are significant wage discrepancies between male and female employees who hold the same position and possess comparable experience and skills.",
58
- "Some male colleagues often make jokes or comments about female employees' appearances and attire, which seems to create an uncomfortable environment. Despite complaints, the issue has not been adequately addressed by management."
59
  ]
60
 
61
- # Gradio app setup
62
  with gr.Blocks() as app:
63
  with gr.Tab("Text Analysis"):
64
  text_input = gr.Textbox(label="Enter Text", placeholder="Type here...", lines=4)
65
  analyze_text_btn = gr.Button("Analyze Text")
66
  text_output = gr.Textbox(label="Analysis Output", lines=6)
67
- examples = gr.Examples(examples=example_scenarios, inputs=text_input, fn=analyze_text, outputs=text_output)
68
  analyze_text_btn.click(
69
  fn=analyze_text,
70
  inputs=text_input,
71
  outputs=text_output
72
  )
 
73
  app.launch()
 
11
  MODEL_ID = "gemini-1.5-pro-002"
12
  model = genai.GenerativeModel(MODEL_ID)
13
 
 
14
  example_model = genai.GenerativeModel(
15
  MODEL_ID,
16
  system_instruction=[
 
20
  )
21
 
22
  # Set model parameters
23
+ generation_config = genai.GenerationConfig(
24
  temperature=0.9,
25
  top_p=1.0,
26
  top_k=32,
 
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
+ gr.Examples(examples=example_scenarios, inputs=text_input, fn=analyze_text, outputs=text_output)
66
  analyze_text_btn.click(
67
  fn=analyze_text,
68
  inputs=text_input,
69
  outputs=text_output
70
  )
71
+
72
  app.launch()