File size: 3,986 Bytes
c3e172c
 
 
 
 
 
 
abee9b3
 
 
c3e172c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abee9b3
c3e172c
 
 
 
 
 
 
 
 
 
 
 
 
 
abee9b3
 
c3e172c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abee9b3
 
6ce173b
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

from flask import Flask, render_template, request, send_from_directory
import requests

with open('cokk.txt', 'r', encoding='utf-8') as file:
    info = file.read()


app = Flask(__name__)

def get_assistant_response(user_input):
    payload = {
        "mode": "chat",
        "chat_history": conversation_history,
        "data": {
            "query": f"{user_input}",
            "loader": "PDFReader",
            "text":""
        }
    }

    response = requests.post(url2, headers=headers, json=payload)
    data = response.json()

    # Extract the response from the data
    response_text = data["data"]["response"]

    response_text = response_text.strip().replace('\n', '<br>')

    # Check if the response contains ~
    if "~" in response_text:
        conversation_history.append({"\n ALex-9": response_text})
        # Extract the prompt between ~~
        prompt_start = response_text.index("~") + 1
        prompt_end = response_text.index("~", prompt_start)
        prompt = response_text[prompt_start:prompt_end]

        # Call the text-to-image API
        image_url = generate_image(prompt)
        response_text += f"<br><br><img src='{image_url}'>"
         # Delete the prompt from the response text
        response_text = response_text.replace("~" + prompt + "~", "")
        prompt = response_text

    return response_text

def generate_image(prompt):
    url = "https://api.braininc.net/be/lambda/function/stableai"
    headers = {
        "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
        "Content-Type": "application/json",
    }

    payload = {
        "json": True,
        "prompt": f"{prompt} Realastic Photo 4K",
        "public_topic": "/studios/516104/wsuid_new-edge-4_nodeid_editor-4/imageGen/1719250632789"
    }

    response = requests.post(url, headers=headers, json=payload)
    data = response.json()

    cdn_url = data["cdn_url"]
    return cdn_url

url2 = "https://api.braininc.net/be/vectordb/indexers/"
headers = {
    "Authorization": "token 72ec00483379076f580eb8126f29da802a5140c3",
    "Content-Type": "application/json;charset=UTF-8",

}

conversation_history = []

@app.route('/')
def home():
    global conversation_history
    conversation_history = []
    conversation_history.append({
        "role": "user",
        "content":f"SYSTEM PROMPT : Hello i hope you are okay , you are AI in my app okay ? so you most follow this : {info}\n \n just make sure to add best greet talk about you in 10 to 15 words okay ? and Start to ask users Quistions and some tips to make good and intresting conversation now let's start",
        "additional_kwargs": {}
    })
    conversation_history.append({
        "role": "assistant",
        "content": "Hello! I'm CLEANER, an AI model trained to teach students the basics of programming in the C language. I'm here to help you understand the course material and prepare for exams. Feel free to ask me any questions or seek guidance on any topic related to C programming. Let's make your learning experience enjoyable and successful! 😊📚 Now, let's begin our conversation. How can I assist you today? Do you have any specific questions or topics you'd like to discuss?",
        "additional_kwargs": {}
    })

    return render_template('ai-chat-bot.html')

@app.route('/get_response', methods=['POST'])
def get_response():
    user_input = request.form['user_input']
    conversation_history.append({
        "role": "user",
        "content":f"{user_input}",
        "additional_kwargs": {}
    })

    if user_input.lower() == "exit":
        return "exit"

    response_text = get_assistant_response(user_input)
    conversation_history.append({
        "role": "assistant",
        "content": f"{response_text}",
        "additional_kwargs": {}
    })
    return response_text

@app.route('/desine/<path:path>')
def send_static(path):
    return send_from_directory('desine', path)

if __name__ == '__main__':
    app.run(host='0.0.0.0' , port=7860)