Update app.py
Browse files
app.py
CHANGED
|
@@ -2,10 +2,11 @@ import gradio as gr
|
|
| 2 |
import random
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
# π§ MEMORY SETUP
|
| 11 |
MEMORY_FILE = "hoopmind_memory.json"
|
|
@@ -32,13 +33,20 @@ def update_memory(user_input):
|
|
| 32 |
save_memory(memory)
|
| 33 |
return memory
|
| 34 |
|
| 35 |
-
# π¬
|
| 36 |
def alpha_chatbot_response(user_input):
|
| 37 |
try:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
return "Oops π I had a lil error trying to respond. Try again in a bit!"
|
| 44 |
|
|
@@ -109,7 +117,7 @@ def hoopmind_chat(user_input, history=[]):
|
|
| 109 |
"Iβm your personal trainer + hype man + homie rolled in one π§ π₯"
|
| 110 |
])
|
| 111 |
|
| 112 |
-
# Fallback: use
|
| 113 |
return alpha_chatbot_response(user_input)
|
| 114 |
|
| 115 |
# π CHAT INTERFACE
|
|
@@ -136,3 +144,4 @@ Drop a question or say what's up π
|
|
| 136 |
chat.launch()
|
| 137 |
|
| 138 |
|
|
|
|
|
|
| 2 |
import random
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
+
import openai
|
| 6 |
|
| 7 |
+
# π SWITCHED TO OPENROUTER + MISTRAL MODEL
|
| 8 |
+
openai.api_base = "https://openrouter.ai/api/v1"
|
| 9 |
+
openai.api_key = "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"
|
| 10 |
|
| 11 |
# π§ MEMORY SETUP
|
| 12 |
MEMORY_FILE = "hoopmind_memory.json"
|
|
|
|
| 33 |
save_memory(memory)
|
| 34 |
return memory
|
| 35 |
|
| 36 |
+
# π¬ General fallback chat using Mistral
|
| 37 |
def alpha_chatbot_response(user_input):
|
| 38 |
try:
|
| 39 |
+
messages = [
|
| 40 |
+
{"role": "system", "content": "You are a helpful, smart, and friendly AI assistant."},
|
| 41 |
+
{"role": "user", "content": user_input}
|
| 42 |
+
]
|
| 43 |
+
response = openai.ChatCompletion.create(
|
| 44 |
+
model="mistral/mistral-7b-instruct", # or "mistral/mixtral-8x7b-instruct"
|
| 45 |
+
messages=messages,
|
| 46 |
+
temperature=0.7,
|
| 47 |
+
max_tokens=200
|
| 48 |
+
)
|
| 49 |
+
return response.choices[0].message["content"].strip()
|
| 50 |
except Exception as e:
|
| 51 |
return "Oops π I had a lil error trying to respond. Try again in a bit!"
|
| 52 |
|
|
|
|
| 117 |
"Iβm your personal trainer + hype man + homie rolled in one π§ π₯"
|
| 118 |
])
|
| 119 |
|
| 120 |
+
# Fallback: use Mistral
|
| 121 |
return alpha_chatbot_response(user_input)
|
| 122 |
|
| 123 |
# π CHAT INTERFACE
|
|
|
|
| 144 |
chat.launch()
|
| 145 |
|
| 146 |
|
| 147 |
+
|