AI_BTC / app.py
Dooratre's picture
Update app.py
c3e172c verified
raw
history blame
3.99 kB
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)