Spaces:
Runtime error
Runtime error
initial commit
Browse files- README.md +8 -5
- assets/chatmagic-ai.png +0 -0
- main.py +71 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.23.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: ChatMagic AI
|
3 |
+
emoji: 🗨️
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.23.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
![ChatMagic AI](https://i.ibb.co/3szrgL8/chatmagic-ai.png)
|
13 |
+
ChatMagic AI is available as an Android app for FREE. Download now to chat faster and better!
|
14 |
+
- Google Play Store URL: **[CLICK HERE](https://bit.ly/googleplaystore-chatmagicai)**
|
15 |
+
- Discord URL: **[CLICK HERE](https://bit.ly/discord-chatmagicai)**
|
assets/chatmagic-ai.png
ADDED
main.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import random
|
5 |
+
import time
|
6 |
+
import os
|
7 |
+
import requests
|
8 |
+
|
9 |
+
|
10 |
+
CHATMAGIC_AI = os.environ["CHATMAGIC_AI"]
|
11 |
+
|
12 |
+
markdown_text = """
|
13 |
+
![ChatMagic AI](https://i.ibb.co/3szrgL8/chatmagic-ai.png)
|
14 |
+
ChatMagic AI is available as an Android app for FREE. Download now to chat faster and better!
|
15 |
+
- Google Play Store URL: **[CLICK HERE](https://bit.ly/googleplaystore-chatmagicai)**
|
16 |
+
- Discord URL: **[CLICK HERE](https://bit.ly/discord-chatmagicai)**
|
17 |
+
"""
|
18 |
+
|
19 |
+
welcome_text = """
|
20 |
+
Hello! I'm ChatMagic AI. I'm here to assist you. I can do the following:
|
21 |
+
1. Answer questions and give explanations
|
22 |
+
2. Assist in writing a text based content
|
23 |
+
3. Follow simple instructions
|
24 |
+
|
25 |
+
However, I still have limitations. I may write incorrect information or produce harmful instructions. Please use me with caution.
|
26 |
+
""".strip()
|
27 |
+
|
28 |
+
|
29 |
+
empty_history = [[None, welcome_text]]
|
30 |
+
|
31 |
+
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown(markdown_text)
|
34 |
+
|
35 |
+
chatbot = gr.Chatbot(empty_history, label="Chat with ChatMagic AI")
|
36 |
+
msg = gr.Textbox(label="Enter your question here")
|
37 |
+
|
38 |
+
with gr.Row() as row:
|
39 |
+
btn_ask = gr.Button("Ask", variant="primary")
|
40 |
+
btn_clear = gr.Button("Clear")
|
41 |
+
|
42 |
+
def user(user_message: str, history: list) -> tuple[str, list]:
|
43 |
+
return "", history + [[user_message, None]]
|
44 |
+
|
45 |
+
def bot(history: list):
|
46 |
+
bot_message = "An error has occured. Please try again."
|
47 |
+
|
48 |
+
try:
|
49 |
+
bot_message = requests.post(CHATMAGIC_AI, json={"question": history[-1][0]}).json()["answer"]
|
50 |
+
except Exception as e:
|
51 |
+
pass
|
52 |
+
|
53 |
+
history[-1][1] = bot_message
|
54 |
+
return history
|
55 |
+
|
56 |
+
msg.submit(
|
57 |
+
fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=True).then(
|
58 |
+
fn=bot, inputs=chatbot, outputs=chatbot
|
59 |
+
)
|
60 |
+
|
61 |
+
btn_ask.click(
|
62 |
+
fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=True).then(
|
63 |
+
fn=bot, inputs=chatbot, outputs=chatbot
|
64 |
+
)
|
65 |
+
|
66 |
+
btn_clear.click(
|
67 |
+
fn=lambda: empty_history, inputs=None, outputs=chatbot, queue=False)
|
68 |
+
|
69 |
+
|
70 |
+
demo.queue(concurrency_count=1)
|
71 |
+
demo.launch(server_name="0.0.0.0")
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
requests
|
3 |
+
Pillow
|