Delete app.py with huggingface_hub
Browse files
app.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
-
from transformers import AutoTokenizer
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
# Import the architecture we defined locally
|
| 7 |
-
sys.path.append('.')
|
| 8 |
-
try:
|
| 9 |
-
from ares_model import AresModel
|
| 10 |
-
except ImportError:
|
| 11 |
-
from ares_project.ares_model import AresModel
|
| 12 |
-
|
| 13 |
-
print("Loading Ares Architecture...")
|
| 14 |
-
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 15 |
-
special_tokens = {'additional_special_tokens': ['<|system|>', '<|user|>', '<|assistant|>', '<|end|>']}
|
| 16 |
-
tokenizer.add_special_tokens(special_tokens)
|
| 17 |
-
VOCAB_SIZE = len(tokenizer)
|
| 18 |
-
|
| 19 |
-
model = AresModel(
|
| 20 |
-
vocab_size=VOCAB_SIZE,
|
| 21 |
-
dim=128,
|
| 22 |
-
n_layers=4,
|
| 23 |
-
n_heads=8,
|
| 24 |
-
hidden_dim=256,
|
| 25 |
-
max_seq_len=512
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
try:
|
| 29 |
-
model.load_state_dict(torch.load("ares_weights.pt", map_location="cpu"))
|
| 30 |
-
print("Successfully loaded trained PyTorch weights!")
|
| 31 |
-
except Exception as e:
|
| 32 |
-
print(f"Warning: Could not load weights: {e}")
|
| 33 |
-
|
| 34 |
-
model.eval()
|
| 35 |
-
|
| 36 |
-
def generate_response(message, history):
|
| 37 |
-
prompt = f"<|system|>You are Ares.<|end|><|user|>{message}<|end|><|assistant|>"
|
| 38 |
-
inputs = tokenizer(prompt, return_tensors="pt")['input_ids']
|
| 39 |
-
|
| 40 |
-
with torch.no_grad():
|
| 41 |
-
outputs = model.generate(
|
| 42 |
-
inputs,
|
| 43 |
-
max_new_tokens=60,
|
| 44 |
-
temperature=0.75,
|
| 45 |
-
repetition_penalty=1.2,
|
| 46 |
-
stop_token=tokenizer.convert_tokens_to_ids("<|end|>")
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=False)
|
| 50 |
-
# Extract only the assistant's response
|
| 51 |
-
reply = response.split("<|assistant|>")[-1].split("<|end|>")[0].strip()
|
| 52 |
-
return reply
|
| 53 |
-
|
| 54 |
-
custom_css = """
|
| 55 |
-
body, .gradio-container { background-color: #0f172a !important; color: #f8fafc !important; font-family: 'Inter', sans-serif !important; }
|
| 56 |
-
h1 { color: #f8fafc; display: flex; align-items: center; gap: 10px; }
|
| 57 |
-
.chatbot { background-color: #1e293b !important; border: 1px solid #334155 !important; border-radius: 12px; }
|
| 58 |
-
.message.user { background-color: #3b82f6 !important; color: white !important; border-radius: 12px 12px 0 12px !important; }
|
| 59 |
-
.message.bot { background-color: #334155 !important; color: white !important; border-radius: 12px 12px 12px 0 !important; }
|
| 60 |
-
#component-0 { border: none !important; box-shadow: none !important; background: transparent !important; }
|
| 61 |
-
textarea { background-color: #0f172a !important; color: white !important; border: 1px solid #334155 !important; border-radius: 24px !important; }
|
| 62 |
-
"""
|
| 63 |
-
|
| 64 |
-
with gr.Blocks(css=custom_css, theme=gr.themes.Monochrome()) as demo:
|
| 65 |
-
gr.HTML("<h1><span style='color:#3b82f6'>●</span> Ares General Intelligence</h1>")
|
| 66 |
-
|
| 67 |
-
chatbot = gr.Chatbot(elem_id="chatbot", label="")
|
| 68 |
-
msg = gr.Textbox(placeholder="Message Ares...", label="", container=False)
|
| 69 |
-
|
| 70 |
-
def user(user_message, history):
|
| 71 |
-
return "", history + [[user_message, None]]
|
| 72 |
-
|
| 73 |
-
def bot(history):
|
| 74 |
-
user_message = history[-1][0]
|
| 75 |
-
bot_message = generate_response(user_message, history)
|
| 76 |
-
history[-1][1] = bot_message
|
| 77 |
-
return history
|
| 78 |
-
|
| 79 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 80 |
-
bot, chatbot, chatbot
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
if __name__ == "__main__":
|
| 84 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|