change to gradio
Browse files- main.py +6 -69
- requirements.txt +1 -0
main.py
CHANGED
@@ -1,71 +1,8 @@
|
|
1 |
-
|
2 |
-
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters, InlineQueryHandler, CallbackContext
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
"role": "system",
|
10 |
-
"content": "Welcome to Grow Bot on telegram"
|
11 |
-
}
|
12 |
-
]
|
13 |
-
|
14 |
-
|
15 |
-
TOKEN= "6058469252:AAEIpuQPvhZfanC1nCrylNCjikYKcXmHMko"
|
16 |
-
def convert_text(text):
|
17 |
-
return text.replace("_", "\\_").replace("*", "\\*").replace("[", "\\[").replace("`", "\\`").replace(".", "\\.")
|
18 |
-
|
19 |
-
|
20 |
-
async def welcome_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
21 |
-
await update.message.reply_text("Welcome to Grow Bot!")
|
22 |
-
|
23 |
-
async def echo_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
24 |
-
input = update.message.text
|
25 |
-
messages.append(
|
26 |
-
{"role": "user", "content": input[6:]}
|
27 |
-
)
|
28 |
-
chat = openai.ChatCompletion.create(
|
29 |
-
model = "gpt-3.5-turbo", messages = messages
|
30 |
-
)
|
31 |
-
reply = chat.choices[0].message.content
|
32 |
-
print("Reply: ", reply)
|
33 |
-
|
34 |
-
await update.message.reply_markdown(f"{reply}")
|
35 |
-
# await update.message.reply_text(f"{reply}")
|
36 |
-
|
37 |
-
async def clear_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
38 |
-
messages = []
|
39 |
-
await update.message.reply_text("Clear context!")
|
40 |
-
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
41 |
-
"""Send a message when the command /help is issued."""
|
42 |
-
await update.message.reply_text("Help!")
|
43 |
-
|
44 |
-
async def non_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
45 |
-
input = update.message.text
|
46 |
-
messages.append(
|
47 |
-
{"role": "user", "content": input}
|
48 |
-
)
|
49 |
-
chat = openai.ChatCompletion.create(
|
50 |
-
model = "gpt-3.5-turbo", messages = messages
|
51 |
-
)
|
52 |
-
messages[-1]["role"] = "assistant"
|
53 |
-
reply = chat.choices[0].message.content
|
54 |
-
print(f"Input: {input}, Reply: {reply}")
|
55 |
-
|
56 |
-
await update.message.reply_markdown(f"{reply}")
|
57 |
-
|
58 |
-
|
59 |
-
def main() -> None:
|
60 |
-
application = Application.builder().token(TOKEN).build()
|
61 |
-
application.add_handler(CommandHandler("welcome", welcome_command))
|
62 |
-
application.add_handler(CommandHandler("echo", echo_command))
|
63 |
-
application.add_handler(CommandHandler("clear", clear_command))
|
64 |
-
application.add_handler(CommandHandler("help", help_command))
|
65 |
-
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, non_command))
|
66 |
-
|
67 |
-
application.run_polling()
|
68 |
-
|
69 |
-
|
70 |
-
if __name__=='__main__':
|
71 |
-
main()
|
|
|
1 |
+
import gradio as gr
|
|
|
2 |
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!"
|
5 |
|
6 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
|
8 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -2,3 +2,4 @@ fastapi
|
|
2 |
uvicorn
|
3 |
python-telegram-bot
|
4 |
openai
|
|
|
|
2 |
uvicorn
|
3 |
python-telegram-bot
|
4 |
openai
|
5 |
+
gradio
|