Spaces:
Running on CPU Upgrade

File size: 2,223 Bytes
a5603d3
7187a61
 
a5603d3
0aa83ad
ee7844e
 
 
7187a61
 
 
a5603d3
 
7187a61
 
a5603d3
 
0aa83ad
 
ee7844e
 
 
0aa83ad
 
 
71c8455
8010cdb
 
 
 
 
7187a61
8010cdb
 
 
 
 
 
 
 
 
 
 
 
 
7187a61
79a1edd
 
76423e6
79a1edd
3b06990
 
 
029c36b
 
 
a52b559
029c36b
 
 
 
3b06990
262ca60
029c36b
 
79a1edd
262ca60
 
 
 
 
79a1edd
 
 
 
3b06990
 
 
 
 
 
79a1edd
7187a61
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import discord
import os
import threading
from discord.ext import commands
import json
import time
import matplotlib.pyplot as plt
from io import BytesIO
import gradio_client
import gradio as gr
from gradio_client import Client


DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
intents = discord.Intents.all() 
bot = commands.Bot(command_prefix='!', intents=intents)



@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')


@bot.command()
async def save_messages(ctx, channel_id: int):
    if ctx.author.id == 811235357663297546:
        channel = bot.get_channel(channel_id)
        if not channel:
            await ctx.send("Channel not found.")
            return
    
        messages = []
        async for message in channel.history(limit=None):
            messages.append(message)
    
        with open("gradio-questions.json", 'w', encoding='utf-8') as file:
            for message in messages:
                file.write(f"{message.content}\n")
    
        await ctx.send(f"Messages from {channel.name} saved to gradio-questions.json")
        
        with open("gradio-questions.json", 'rb') as file:
            discord_file = discord.File(file)
            await ctx.send(file=discord_file)


@bot.command()
async def save_forum(ctx, channel_id: int):
    channel = bot.get_channel(channel_id)
    threads = channel.threads




    messages = []
    for thread in threads:
        async for message in thread.history(limit=None):
            messages.append(message)

    print(messages) # debug

    with open("gradio-questions.json", 'w', encoding='utf-8') as file:
        for message in messages:
            file.write(f"{message.content}\n")

    await ctx.send(f"Messages from {channel.name} saved to gradio-questions.json")
    
    with open("gradio-questions.json", 'rb') as file:
        discord_file = discord.File(file)
        await ctx.send(file=discord_file)









        

        
""""""
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
def run_bot():
    bot.run(DISCORD_TOKEN)
threading.Thread(target=run_bot).start()
def greet(name):
    return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()