NihalGazi commited on
Commit
56df8ed
ยท
verified ยท
1 Parent(s): 286c543

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ from discord.ext import commands
3
+ import threading
4
+ import gradio as gr
5
+
6
+ # ==== Discord Bot Setup ====
7
+ intents = discord.Intents.default()
8
+ intents.reactions = True
9
+ intents.messages = True
10
+
11
+ bot = commands.Bot(command_prefix="!", intents=intents)
12
+
13
+ # Dummy translate function
14
+ def translate(text, target_language):
15
+ return f"[{target_language} translation of] {text}"
16
+
17
+ flag_to_language = {
18
+ "๐Ÿ‡ซ๐Ÿ‡ท": "fr", # French
19
+ "๐Ÿ‡ฉ๐Ÿ‡ช": "de", # German
20
+ "๐Ÿ‡ช๐Ÿ‡ธ": "es", # Spanish
21
+ "๐Ÿ‡ฎ๐Ÿ‡น": "it", # Italian
22
+ "๐Ÿ‡ฌ๐Ÿ‡ง": "en", # English
23
+ "๐Ÿ‡ท๐Ÿ‡บ": "ru", # Russian
24
+ }
25
+
26
+ @bot.event
27
+ async def on_ready():
28
+ print(f"Logged in as {bot.user}")
29
+
30
+ @bot.event
31
+ async def on_reaction_add(reaction, user):
32
+ if user.bot:
33
+ return
34
+ if reaction.message.author.bot:
35
+ return
36
+
37
+ emoji = reaction.emoji
38
+ if emoji in flag_to_language:
39
+ target_lang = flag_to_language[emoji]
40
+ original_text = reaction.message.content
41
+ translated_text = translate(original_text, target_lang)
42
+ await reaction.message.channel.send(f"Translated to {target_lang}: {translated_text}")
43
+
44
+ def run_discord_bot():
45
+ bot.run("MTM1MjI2OTQ4MTQwNTE4NjA3MA.GrdeHW.rYndSNvb9mepFdp_uTK4IOAmKwt31QER6hRgzg")
46
+
47
+ # Start Discord bot in a separate thread
48
+ threading.Thread(target=run_discord_bot, daemon=True).start()
49
+
50
+ # ==== Gradio Interface ====
51
+ def process_input(text):
52
+ if not text.strip():
53
+ return "OK"
54
+ return text
55
+
56
+ # Gradio UI
57
+ iface = gr.Interface(
58
+ fn=process_input,
59
+ inputs=gr.Textbox(label="Enter something"),
60
+ outputs=gr.Textbox(label="Output"),
61
+ live=True,
62
+ )
63
+
64
+ iface.launch()