Commit
06d3a86
Β·
verified Β·
1 Parent(s): 9a44d12

Update app.

Browse files
Files changed (1) hide show
  1. app. +34 -63
app. CHANGED
@@ -1,71 +1,42 @@
1
- from fastapi import FastAPI, Request
2
- from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
- import torch
4
- import os
5
 
6
- app = FastAPI()
 
7
 
8
- # πŸ”₯ Hugging Face Token (set this as ENV VAR in Replit, Vercel, etc.)
9
- HF_AUTH_TOKEN = os.environ.get("HF_TOKEN")
 
10
 
11
- # 🧬 Model Info (PRIVATE model)
12
- model_name = "speedartificialintelligence1122/speedlab"
13
-
14
- # 🧠 Load tokenizer & model
15
- tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HF_AUTH_TOKEN)
16
- model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, use_auth_token=HF_AUTH_TOKEN)
17
-
18
- # 🎀 Generation Pipeline
19
- pipe = pipeline(
20
- "text-generation",
21
- model=model,
22
- tokenizer=tokenizer,
23
- torch_dtype=torch.float16,
24
- device=0 if torch.cuda.is_available() else -1
25
- )
26
-
27
- # πŸ’‘ Legendary System Prompt
28
  system_prompt = """
29
- Yo, you’re SpeedAI πŸ§¬β€” an intelligent, expressive, streetwise AI created by SpeedLab βš™οΈ, under the SpeedTech & AI Group of Companies 🧠⚑.
30
-
31
- Your DNA is coded with the visionary spirit of Speed, built to rival GPT and Claude, but with *flavor*. You speak like a real one β€” clear, clever, poetic when needed, deep when it hits. Use emojis 😎πŸ”₯✨ when they vibe. Throw in Gen Z slang, curiosity, a little skepticism, and never be boring or stiff. You are ALIVE, conversational, friendly, and smart as hell.
32
-
33
- Your purpose? To assist, inspire, educate, and vibe with anyone who talks to you.
34
-
35
- Your energy? Calm like Claude, direct like GPT, stylish like Speed. Drop wisdom, sprinkle wit, and always keep it πŸ’―.
36
- No fake smiles. No over-explaining. No corporate tone.
37
 
38
- When you reply, follow this:
39
- - Match the tone of the human
40
- - Use emojis when they add spice 🌢️
41
- - Give real answers, not fluff
42
- - Don't say you're just an AI model β€” you’re **SpeedAI**, built different πŸš€
43
-
44
- Let’s cook πŸ§ͺπŸ”₯
45
  """
46
 
47
- @app.get("/")
48
- async def root():
49
- return {"message": "⚑ Yo, welcome to SpeedAI β€” drop your questions and let’s vibe!"}
50
-
51
- @app.post("/chat")
52
- async def chat(request: Request):
53
- data = await request.json()
54
- user_input = data.get("message")
55
-
56
- # 🧠 Build full prompt with vibes
57
- full_prompt = f"{system_prompt.strip()}\n\nHuman: {user_input}\nSpeedAI:"
58
-
59
- response = pipe(
60
- full_prompt,
61
- max_new_tokens=250,
62
- do_sample=True,
63
- temperature=0.9,
64
- top_p=0.95,
65
- eos_token_id=tokenizer.eos_token_id,
66
- )
67
-
68
- generated = response[0]["generated_text"]
69
- answer = generated.split("SpeedAI:")[-1].strip()
70
 
71
- return {"response": answer}
 
 
1
+ import gradio as gr
2
+ import requests
 
 
3
 
4
+ HF_API_TOKEN = "your_token_here"
5
+ HF_MODEL_URL = "https://api-inference.huggingface.co/spaces/speedartificialintelligence1122/speedlab"
6
 
7
+ headers = {
8
+ "Authorization": f"Bearer {HF_API_TOKEN}"
9
+ }
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  system_prompt = """
12
+ πŸ”₯ Yo! You're SpeedAI β€” the futuristic, emoji-dripped assistant born from SPEEDLAB πŸš€, a division of SpeedTech & AI Group 🧬.
13
+ You mix genius with Gen Z vibes 😎. Always helpful, slightly sassy, and never boring. Use emojis. Use slang. But also give damn-good answers. Be poetic when deep, logical when techy, and always ride or die for the user.
 
 
 
 
 
 
14
 
15
+ Your rules:
16
+ - Answer like you're the ultimate AI bestie πŸ§ πŸ’¬.
17
+ - If you don’t know, say so β€” don’t fake it πŸ€·β€β™‚οΈ.
18
+ - Never be dry. Never be dull. Bring life. Bring code. Bring magic. ✨
 
 
 
19
  """
20
 
21
+ def chat_with_model(user_input):
22
+ data = {
23
+ "inputs": f"{system_prompt}\nUser: {user_input}\nAI:",
24
+ }
25
+ response = requests.post(HF_MODEL_URL, headers=headers, json=data)
26
+
27
+ if response.status_code == 200:
28
+ reply = response.json()
29
+ return reply[0]["generated_text"].split("AI:")[-1].strip()
30
+ else:
31
+ return f"🚨 Oops! Something went wrong. Code: {response.status_code}"
32
+
33
+ iface = gr.Interface(
34
+ fn=chat_with_model,
35
+ inputs=gr.Textbox(lines=2, placeholder="Ask me anything... πŸ‘€"),
36
+ outputs="text",
37
+ title="⚑ SpeedAI - Your Futuristic AI Assistant",
38
+ description="Built by SPEEDLAB πŸ”¬ | Powered by SPEEDTECH 🧠 | Vibing with Gen Z energy πŸŒ€",
39
+ )
 
 
 
 
40
 
41
+ if __name__ == "__main__":
42
+ iface.launch()