wop commited on
Commit
13b8c1f
1 Parent(s): ece4edf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -32
app.py CHANGED
@@ -4,12 +4,11 @@ import threading
4
  from threading import Event
5
  from typing import Optional
6
 
7
- import asyncio
8
  import datetime
9
  import requests
10
  import discord
11
  import gradio as gr
12
- import gradio_client as grc
13
  from discord import Permissions
14
  from discord.ext import commands
15
  from discord.utils import oauth_url
@@ -45,38 +44,17 @@ async def uptime(ctx):
45
  @bot.command()
46
  async def ai(ctx, *, input_text: str):
47
  """Ask our AI model a question. (Session resets every 1 message!)"""
48
-
49
- try:
50
- client = grc.Client("https://wop-xxx-opengpt.hf.space/")
51
-
52
- # Remove leading and trailing whitespace from the input text
53
- input_text = input_text.strip()
54
-
55
- # Asynchronously make the prediction request
56
- prediction_task = asyncio.create_task(client.predict(
57
- input_text,
58
- 0.9,
59
- 1800,
60
- 0.9,
61
- 1.2,
62
- api_name="/chat"
63
- ))
64
 
65
- # Wait for the prediction task to complete
66
- result = await prediction_task
67
-
68
- # Truncate the last 4 characters from the result (if necessary)
69
- result = result[:-4]
70
-
71
- # Create an embed with the AI's response
72
- embed = discord.Embed(title="AI Response", description=result, color=discord.Color.green())
73
- embed.add_field(name="Info", value="Session resets every `1` message!\nModel Name: `Mistral 7B`", inline=False)
74
- embed.set_footer(text="Created by Cosmos")
75
 
76
- # Reply with the embed
77
- await ctx.send(embed=embed)
78
- except Exception as e:
79
- await ctx.send(f"An error occurred: {str(e)}")
80
 
81
 
82
  @bot.command()
 
4
  from threading import Event
5
  from typing import Optional
6
 
 
7
  import datetime
8
  import requests
9
  import discord
10
  import gradio as gr
11
+ from gradio_client import Client
12
  from discord import Permissions
13
  from discord.ext import commands
14
  from discord.utils import oauth_url
 
44
  @bot.command()
45
  async def ai(ctx, *, input_text: str):
46
  """Ask our AI model a question. (Session resets every 1 message!)"""
47
+ client = Client("https://wop-xxx-opengpt.hf.space/")
48
+ result = client.predict(input_text, 0.9, 2000, 0.9, 1.2, api_name="/chat")
49
+ result = result[:-4]
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ # Create an embed with the AI's response
52
+ embed = discord.Embed(title="AI Response", description=result, color=discord.Color.green())
53
+ embed.add_field(name="Info", value="Session resets every `1` message!\nModel Name: `Mistral 7B`", inline=False)
54
+ embed.set_footer(text="Created by Cosmos")
 
 
 
 
 
 
55
 
56
+ # Reply with the embed
57
+ await ctx.send(embed=embed)
 
 
58
 
59
 
60
  @bot.command()