muhammadharis222 commited on
Commit
28f61a9
Β·
verified Β·
1 Parent(s): 1636049

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -22
app.py CHANGED
@@ -6,9 +6,7 @@ from google import genai
6
  client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
7
 
8
  def get_definitions(text):
9
- """
10
- Fetch dictionary-like definitions for multiple words using Gemini.
11
- """
12
  if not text.strip():
13
  return "⚠️ Please enter one or more words."
14
 
@@ -17,14 +15,16 @@ def get_definitions(text):
17
 
18
  for word in words:
19
  prompt = f"""
20
- You are a creative and accurate dictionary assistant.
21
- Provide a clear, concise definition, pronunciation, and example
22
  for the word "{word}".
23
- Format neatly using markdown with emojis and structure like:
24
- **Word:** ...
25
- **Pronunciation:** ...
26
- **Definition:** ...
27
- **Example:** ...
 
 
28
  """
29
  try:
30
  response = client.models.generate_content(
@@ -37,33 +37,76 @@ def get_definitions(text):
37
 
38
  return "\n\n---\n\n".join(results)
39
 
40
- # --- CSS for modern UI ---
41
  custom_css = """
42
- body {background: linear-gradient(to bottom right, #1e3c72, #2a5298);}
43
- .gradio-container {font-family: 'Inter', sans-serif;}
44
- .gr-button {background-color: #4CAF50 !important; color: white !important;}
45
- .gr-text-input {border-radius: 10px !important;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  footer {display:none !important;}
47
  """
48
 
49
  # --- Gradio UI ---
50
  with gr.Blocks(css=custom_css, title="Modern AI Dictionary") as demo:
51
- gr.Markdown("<h1 style='text-align:center; color:white;'>πŸ“˜ Modern AI Dictionary</h1>")
52
- gr.Markdown("<p style='text-align:center; color:#e0e0e0;'>Enter multiple words separated by commas.</p>")
53
 
54
- with gr.Row():
55
  word_input = gr.Textbox(
56
  placeholder="e.g. serendipity, eloquent, ephemeral",
57
  label="Enter word(s)",
58
  lines=2
59
  )
60
- with gr.Row():
61
- output = gr.Markdown()
62
- with gr.Row():
63
  btn = gr.Button("πŸ” Get Meanings")
 
 
 
64
 
65
  btn.click(fn=get_definitions, inputs=word_input, outputs=output)
66
 
67
- # Launch app
68
  if __name__ == "__main__":
69
  demo.launch()
 
6
  client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
7
 
8
  def get_definitions(text):
9
+ """Fetch dictionary-like definitions for multiple words using Gemini."""
 
 
10
  if not text.strip():
11
  return "⚠️ Please enter one or more words."
12
 
 
15
 
16
  for word in words:
17
  prompt = f"""
18
+ You are a helpful, modern dictionary assistant.
19
+ Provide a clear, concise definition, pronunciation, part of speech, and an example
20
  for the word "{word}".
21
+ Format neatly using markdown like this:
22
+
23
+ πŸͺΆ **Word:** ...
24
+ πŸ”Š **Pronunciation:** ...
25
+ πŸ“˜ **Part of Speech:** ...
26
+ πŸ’‘ **Definition:** ...
27
+ ✨ **Example:** ...
28
  """
29
  try:
30
  response = client.models.generate_content(
 
37
 
38
  return "\n\n---\n\n".join(results)
39
 
40
+ # --- Modern soft theme CSS ---
41
  custom_css = """
42
+ body {
43
+ background: linear-gradient(135deg, #f0f4ff, #e8f0fe);
44
+ font-family: 'Inter', sans-serif;
45
+ }
46
+
47
+ .gradio-container {
48
+ max-width: 800px !important;
49
+ margin: auto;
50
+ padding-top: 40px;
51
+ }
52
+
53
+ h1 {
54
+ color: #2b2d42;
55
+ font-weight: 700;
56
+ }
57
+
58
+ .gr-text-input, .gr-button, .gr-markdown {
59
+ border-radius: 12px !important;
60
+ }
61
+
62
+ .gr-text-input {
63
+ background-color: #ffffff !important;
64
+ border: 1px solid #d3d9f0 !important;
65
+ box-shadow: 0px 2px 6px rgba(0,0,0,0.05);
66
+ margin-bottom: 20px !important;
67
+ }
68
+
69
+ .gr-button {
70
+ background-color: #4c6ef5 !important;
71
+ color: white !important;
72
+ font-weight: 600 !important;
73
+ transition: 0.3s;
74
+ box-shadow: 0px 2px 6px rgba(0,0,0,0.1);
75
+ }
76
+
77
+ .gr-button:hover {
78
+ background-color: #364fc7 !important;
79
+ }
80
+
81
+ .output-card {
82
+ background-color: #ffffff;
83
+ border: 1px solid #dee2f0;
84
+ border-radius: 12px;
85
+ padding: 20px;
86
+ box-shadow: 0 4px 10px rgba(0,0,0,0.05);
87
+ margin-top: 30px;
88
+ }
89
  footer {display:none !important;}
90
  """
91
 
92
  # --- Gradio UI ---
93
  with gr.Blocks(css=custom_css, title="Modern AI Dictionary") as demo:
94
+ gr.Markdown("<h1 style='text-align:center;'>πŸ“˜ Modern AI Dictionary</h1>")
95
+ gr.Markdown("<p style='text-align:center; color:#555;'>Type multiple words separated by commas to explore their meanings.</p>")
96
 
97
+ with gr.Column():
98
  word_input = gr.Textbox(
99
  placeholder="e.g. serendipity, eloquent, ephemeral",
100
  label="Enter word(s)",
101
  lines=2
102
  )
103
+
 
 
104
  btn = gr.Button("πŸ” Get Meanings")
105
+
106
+ with gr.Column(elem_classes="output-card"):
107
+ output = gr.Markdown()
108
 
109
  btn.click(fn=get_definitions, inputs=word_input, outputs=output)
110
 
 
111
  if __name__ == "__main__":
112
  demo.launch()