artintel235 commited on
Commit
f7da1a2
·
verified ·
1 Parent(s): 8ad5407

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -8,8 +8,6 @@ import gradio as gr # Import Gradio
8
  import google.generativeai as genai
9
  from io import BytesIO
10
  import PIL.Image
11
- import base64
12
- from typing import List
13
  # --- Environment Variables & Setup ---
14
  DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
15
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
@@ -18,9 +16,6 @@ intents = discord.Intents.default()
18
  client = discord.Client(intents=intents)
19
  tree = app_commands.CommandTree(client)
20
 
21
- genai.configure(api_key=GEMINI_API_KEY)
22
- model = genai.GenerativeModel("gemini-2.0-flash-exp")
23
-
24
  if not DISCORD_BOT_TOKEN or not GEMINI_API_KEY:
25
  raise ValueError("Both DISCORD_BOT_TOKEN and GEMINI_API_KEY must be set.")
26
 
@@ -28,16 +23,27 @@ if not DISCORD_BOT_TOKEN or not GEMINI_API_KEY:
28
  async def hello_command(interaction):
29
  await interaction.response.send_message("Hello there!")
30
 
 
 
 
 
 
 
 
 
 
 
31
  async def generate_command(
32
  interaction: discord.Interaction,
33
  prompt: str,
 
 
34
  ):
35
  try:
36
- await interaction.response.defer()
37
  genai.configure(api_key=GEMINI_API_KEY)
38
  model = genai.GenerativeModel("gemini-2.0-flash-exp")
39
  response = model.generate_content(prompt, stream=True)
40
-
41
  current_message = None # Initialize outside the loop to keep track of current message
42
  current_message_content = ""
43
 
@@ -66,11 +72,10 @@ async def generate_command(
66
  await current_message.edit(content=current_message_content)
67
  else:
68
  await interaction.followup.send(content=current_message_content)
69
-
70
  except Exception as e:
71
  print(e)
72
 
73
-
74
  async def on_ready():
75
  await tree.sync()
76
  print("Bot is ready!")
@@ -101,5 +106,3 @@ async def main():
101
 
102
  if __name__ == "__main__":
103
  asyncio.run(main())
104
-
105
-
 
8
  import google.generativeai as genai
9
  from io import BytesIO
10
  import PIL.Image
 
 
11
  # --- Environment Variables & Setup ---
12
  DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
13
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
 
16
  client = discord.Client(intents=intents)
17
  tree = app_commands.CommandTree(client)
18
 
 
 
 
19
  if not DISCORD_BOT_TOKEN or not GEMINI_API_KEY:
20
  raise ValueError("Both DISCORD_BOT_TOKEN and GEMINI_API_KEY must be set.")
21
 
 
23
  async def hello_command(interaction):
24
  await interaction.response.send_message("Hello there!")
25
 
26
+ @tree.command(name="gemini", description="chat with gemini")
27
+ # @app_commands.choices(
28
+ # aspect_ratio=[
29
+ # app_commands.Choice(name="1:1 (Square)", value="1:1"),
30
+ # app_commands.Choice(name="9:16 (Vertical)", value="9:16"),
31
+ # app_commands.Choice(name="16:9 (Horizontal)", value="16:9"),
32
+ # app_commands.Choice(name="3:4", value="3:4"),
33
+ # app_commands.Choice(name="4:3", value="4:3"),
34
+ # ]
35
+ # )
36
  async def generate_command(
37
  interaction: discord.Interaction,
38
  prompt: str,
39
+ # img_count: int,
40
+ # aspect_ratio: app_commands.Choice[str],
41
  ):
42
  try:
43
+ await interaction.response.defer() # Defer the interaction
44
  genai.configure(api_key=GEMINI_API_KEY)
45
  model = genai.GenerativeModel("gemini-2.0-flash-exp")
46
  response = model.generate_content(prompt, stream=True)
 
47
  current_message = None # Initialize outside the loop to keep track of current message
48
  current_message_content = ""
49
 
 
72
  await current_message.edit(content=current_message_content)
73
  else:
74
  await interaction.followup.send(content=current_message_content)
 
75
  except Exception as e:
76
  print(e)
77
 
78
+
79
  async def on_ready():
80
  await tree.sync()
81
  print("Bot is ready!")
 
106
 
107
  if __name__ == "__main__":
108
  asyncio.run(main())