Rahatara commited on
Commit
8e000a7
1 Parent(s): b55a481

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -99
app.py DELETED
@@ -1,99 +0,0 @@
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
7
- GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
8
- genai.configure(api_key=GOOGLE_API_KEY)
9
- MODEL_ID = "gemini-1.5-pro-002"
10
- model = genai.GenerativeModel(MODEL_ID)
11
-
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
-
20
- # Set model parameters
21
- generation_config = genai.GenerationConfig(
22
- temperature=0.9,
23
- top_p=1.0,
24
- top_k=32,
25
- candidate_count=1,
26
- max_output_tokens=8192,
27
- )
28
-
29
- # Safety and instruction settings
30
- safety_settings = {
31
- HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
32
- HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
33
- HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
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
-
67
- # Example scenarios for gender discrimination analysis
68
- example_scenarios = [
69
- "During a team meeting, whenever a female colleague tried to express her opinion, she was often interrupted or talked over by male colleagues.",
70
- "The feedback given to female employees often focuses more on their demeanor and less on their actual accomplishments.",
71
- "Male employees are more frequently considered for promotions and challenging projects, even when female employees have similar or superior qualifications.",
72
- "During a hiring panel, female candidates were often asked about their personal life, family plans, and how they would balance home and work.",
73
- "There are significant wage discrepancies between male and female employees who hold the same position and possess comparable experience.",
74
- "Some male colleagues often make inappropriate jokes or comments about female employees' appearances and attire."
75
- ]
76
-
77
- # Gradio interface setup
78
- with gr.Blocks(css=css) as app:
79
- gr.Markdown("<div id='logo'>J<span>ustEva</span></div>")
80
- gr.Markdown("<h1 style='text-align: center; color: #5f4b8b;'>Gender Bias Analysis Platform</h1>")
81
- gr.Markdown("<p style='text-align: center; font-size: 16px; color: #4a4a4a;'>Powered by AI to advocate against gender-based violence</p>")
82
- with gr.Tab("Text Analysis"):
83
- text_input = gr.Textbox(label="Enter Text or Select an Example", placeholder="Type here or select an example...", lines=4)
84
- analyze_text_btn = gr.Button("Analyze Text")
85
- text_output = gr.Textbox(label="Analysis Output", lines=6)
86
-
87
- examples = gr.Examples(
88
- examples=example_scenarios,
89
- inputs=text_input,
90
- outputs=text_output
91
- )
92
-
93
- analyze_text_btn.click(
94
- fn=analyze_text,
95
- inputs=text_input,
96
- outputs=text_output
97
- )
98
-
99
- app.launch()