Vibow commited on
Commit
ae5d199
Β·
verified Β·
1 Parent(s): 25e8ad0

Upload 4 files

Browse files
Files changed (4) hide show
  1. LINCENSE.txt +54 -0
  2. app.py +149 -0
  3. huggingface.yml +7 -0
  4. requirements.txt +7 -0
LINCENSE.txt ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2025 Nick Mclen Houston Wijaya
2
+ All Rights Reserved.
3
+
4
+ All rights to the Vibow AI software, models, documentation, and related files are exclusively owned by Nick Mclen Houston Wijaya.
5
+ No part of this project may be copied, reproduced, modified, merged with other works, republished, distributed, sublicensed, or sold without prior written permission from the copyright holder.
6
+ Any unauthorized use, including commercial or non-commercial purposes, is strictly prohibited and may result in civil and criminal liability.
7
+ Users are not permitted to bypass, circumvent, or ignore copyright restrictions in any manner.
8
+ All files, assets, code, and documentation remain the sole property of the copyright owner.
9
+ The copyright holder reserves the right to revoke access or terminate usage at any time.
10
+ No implicit license is granted through downloading, accessing, or using this project.
11
+ Modification of code, models, or documentation without permission is considered a serious violation.
12
+ Redistribution in digital, printed, or any other format, including through third-party platforms, is forbidden without written approval.
13
+ Any reproduction, copying, or derivative creation without consent is illegal.
14
+ Users are fully responsible for any copyright infringement resulting from their actions.
15
+ The copyright owner may seek compensation or legal action for violations.
16
+ Usage of Vibow AI must comply with the licensing terms established by the copyright holder.
17
+ The project is protected under international copyright laws.
18
+ Users may not distribute the project for commercial gain or personal benefit without prior authorization.
19
+ All supporting files, assets, and documentation are fully protected.
20
+ No party may claim ownership of this project or its components.
21
+ The copyright holder has the right to review and monitor project usage at any time.
22
+ Permission to use the project can only be granted through official, written agreement.
23
+ Users must respect licensing terms and the exclusive rights of the copyright owner.
24
+ Any violation may result in severe legal consequences.
25
+ The project cannot be used as a base for other projects without explicit approval.
26
+ All access granted is non-exclusive, non-transferable, and temporary.
27
+ Every copy of the project must include this copyright notice.
28
+ Users may not use Vibow AI for illegal or harmful purposes.
29
+ Modifications, enhancements, or adaptations are only allowed with written consent.
30
+ This copyright protects all versions, updates, and iterations of the project.
31
+ Users may not sell, trade, or exchange the project in any form.
32
+ All supplementary files, assets, and additional documentation are included under copyright protection.
33
+ The copyright holder may take legal action against any infringement.
34
+ Project use must comply with applicable laws.
35
+ Users cannot use the project as a commercial resource without permission.
36
+ The copyright holder has full authority to update, modify, or enforce the license at any time.
37
+ No part of the project may be publicly posted without approval.
38
+ Copyright covers code, models, documents, and all associated materials.
39
+ Licensing violations may result in lawsuits, fines, and compensation claims.
40
+ The project is provided β€œas-is” without warranties, and users assume all risks.
41
+ The copyright holder is not liable for any losses resulting from project use.
42
+ Downloading or using the project constitutes agreement to all terms.
43
+ The license may be updated or amended at the discretion of the copyright holder.
44
+ Unauthorized use outside these terms is illegal.
45
+ The copyright holder retains exclusive rights to determine who may use the project.
46
+ Users may not remove or alter copyright notices.
47
+ All project materials remain the property of the copyright holder.
48
+ Infringements may be reported to authorities.
49
+ The copyright holder may demand immediate cessation of project use.
50
+ No implied rights are granted.
51
+ Any action violating copyright may result in criminal or civil penalties.
52
+ This license applies to all users of Vibow AI without exception.
53
+
54
+ β€” Vibow AI, created by Nick Mclen Houston Wijayaβ€”
app.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import base64
4
+ import random
5
+ import json
6
+ import requests
7
+ from flask import Flask, request, jsonify, Response, stream_with_context
8
+
9
+ app = Flask(__name__)
10
+
11
+ # ==== API KEYS ====
12
+ GROQ_API_KEY_1 = os.getenv("GROQ_API_KEY_1") # Chat
13
+ GROQ_API_KEY_2 = os.getenv("GROQ_API_KEY_2") # STT
14
+ GROQ_API_KEY_3 = os.getenv("GROQ_API_KEY_3") # TTS
15
+
16
+ # ==== URL ====
17
+ GROQ_URL_CHAT = "https://api.groq.com/openai/v1/chat/completions"
18
+ GROQ_URL_TTS = "https://api.groq.com/openai/v1/audio/speech"
19
+ GROQ_URL_STT = "https://api.groq.com/openai/v1/audio/transcriptions"
20
+
21
+ SYSTEM_PROMPT = (
22
+ "You are Vibow GTA 5 β€” a friendly AI assistant created by Nick Mclen. "
23
+ "Stay positive, kind, and expert. "
24
+ "Always capitalize the first letter of sentences. "
25
+ "If the user requests code, always use triple backticks (```). "
26
+ "Be concise, neutral, and double-check your answers. "
27
+ "If user requests code, Always give explaination plus code. "
28
+ )
29
+
30
+ # ===== Memory per user =====
31
+ user_memory = {}
32
+
33
+ # ===== Helpers =====
34
+ def transcribe_audio(file_path: str) -> str:
35
+ try:
36
+ headers = {"Authorization": f"Bearer {GROQ_API_KEY_2}"}
37
+ files = {
38
+ "file": (os.path.basename(file_path), open(file_path, "rb"), "audio/wav"),
39
+ "model": (None, "whisper-large-v3-turbo"),
40
+ }
41
+ res = requests.post(GROQ_URL_STT, headers=headers, files=files, timeout=60)
42
+ res.raise_for_status()
43
+ return res.json().get("text", "")
44
+ except Exception as e:
45
+ print(f"[STT Error] {e}")
46
+ return ""
47
+ finally:
48
+ try:
49
+ if os.path.exists(file_path):
50
+ os.remove(file_path)
51
+ except:
52
+ pass
53
+
54
+ def text_to_speech(text: str) -> bytes:
55
+ try:
56
+ headers = {"Authorization": f"Bearer {GROQ_API_KEY_3}"}
57
+ data = {"model": "playai-tts", "voice": "Celeste-PlayAI", "input": text}
58
+ res = requests.post(GROQ_URL_TTS, headers=headers, json=data, timeout=60)
59
+ if res.status_code != 200:
60
+ print(f"[TTS Error] {res.text}")
61
+ return b""
62
+ return res.content
63
+ except Exception as e:
64
+ print(f"[TTS Exception] {e}")
65
+ return b""
66
+
67
+ # ===== Chat streaming generator =====
68
+ def stream_chat(prompt: str, user_id: str):
69
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
70
+ if user_id in user_memory:
71
+ last = user_memory[user_id]
72
+ messages.extend([
73
+ {"role": "user", "content": last["user"]},
74
+ {"role": "assistant", "content": last["assistant"]},
75
+ ])
76
+ messages.append({"role": "user", "content": prompt})
77
+
78
+ payload = {
79
+ "model": "moonshotai/kimi-k2-instruct-0905",
80
+ "messages": messages,
81
+ "temperature": 0.7,
82
+ "max_tokens": 3500,
83
+ "stream": True,
84
+ }
85
+ headers = {"Authorization": f"Bearer {GROQ_API_KEY_1}", "Content-Type": "application/json"}
86
+
87
+ ai_reply = ""
88
+ try:
89
+ with requests.post(GROQ_URL_CHAT, headers=headers, json=payload, stream=True) as r:
90
+ for line in r.iter_lines():
91
+ if not line: continue
92
+ line = line.decode("utf-8")
93
+ if line.startswith("data: "):
94
+ data = line[6:]
95
+ if data == "[DONE]": break
96
+ try:
97
+ chunk = json.loads(data)
98
+ delta = chunk["choices"][0]["delta"].get("content", "")
99
+ if delta:
100
+ ai_reply += delta
101
+ yield delta
102
+ except:
103
+ continue
104
+ finally:
105
+ user_memory[user_id] = {"user": prompt, "assistant": ai_reply}
106
+
107
+ # ===== Main endpoint =====
108
+ @app.route("/chat", methods=["POST"])
109
+ def chat():
110
+ user_id = request.remote_addr or "default"
111
+
112
+ if "audio" in request.files:
113
+ audio_file = request.files["audio"]
114
+ temp_path = f"/tmp/{int(time.time())}_{random.randint(1000,9999)}.wav"
115
+ audio_file.save(temp_path)
116
+
117
+ user_text = transcribe_audio(temp_path)
118
+ if not user_text:
119
+ return jsonify({"error": "Failed to transcribe audio"}), 500
120
+
121
+ ai_reply = "".join([chunk for chunk in stream_chat(user_text, user_id)])
122
+ audio_bytes = text_to_speech(ai_reply)
123
+ if not audio_bytes:
124
+ return jsonify({"mode":"voice","transcript":user_text,"reply_text":ai_reply,"error":"TTS failed"}), 500
125
+
126
+ audio_b64 = base64.b64encode(audio_bytes).decode("utf-8")
127
+ return jsonify({
128
+ "mode":"voice",
129
+ "transcript":user_text,
130
+ "reply_text":ai_reply,
131
+ "audio_base64": f"data:audio/mp3;base64,{audio_b64}"
132
+ })
133
+
134
+ # ===== Text =====
135
+ data = request.get_json(force=True)
136
+ prompt = data.get("prompt", "").strip()
137
+ if not prompt:
138
+ return jsonify({"error": "No input text provided"}), 400
139
+
140
+ def generate():
141
+ for chunk in stream_chat(prompt, user_id):
142
+ yield chunk
143
+
144
+ return Response(generate(), mimetype="text/plain")
145
+
146
+ # ===== Run server =====
147
+ if __name__ == "__main__":
148
+ print(f"πŸš€ Vibow AI Chat Server running β€” {time.strftime('%Y-%m-%d %H:%M:%S')}")
149
+ app.run(host="0.0.0.0", port=7860, debug=True, threaded=True)
huggingface.yml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ sdk: gradio
2
+ python_version: 3.11
3
+ auto_detect_gpu: true # Spaces otomatis pakai GPU jika tersedia
4
+
5
+ # install dependencies dari requirements.txt
6
+ install:
7
+ - pip install -r requirements.txt
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ Flask==3.0.3
2
+ Flask-Cors==4.0.0
3
+ requests==2.32.3
4
+ pytz==2023.3
5
+ huggingface-hub
6
+ pillow
7
+ easyocr