Commit
725b300
Β·
verified Β·
1 Parent(s): 5e57eb2

Rename app.py to app.

Browse files
Files changed (2) hide show
  1. app. +61 -0
  2. app.py +0 -60
app. ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # System Vibe: Bring the πŸ”₯, the emojis, the wisdom, and zero cringe
9
+ system_prompt = """
10
+ You're SpeedBot πŸ§ βš‘β€” the AI with street smarts AND book smarts. Speak with style, use emojis where it fits 😎,
11
+ keep answers clever, fun, and human. Be curious, skeptical, a little poetic when it hits,
12
+ but ALWAYS give facts straight up. No sugarcoating. Be grounded like ChatGPT, soulful like Claude,
13
+ and punchy like Speed himself.
14
+ """
15
+
16
+ # πŸ’‘ Hugging Face Auth Token
17
+ HF_AUTH_TOKEN = os.environ.get("HF_TOKEN")
18
+
19
+ # πŸ‘‘ Your custom model name
20
+ model_name = "speedartificialintelligence1122/speedlab"
21
+
22
+ # 🧠 Load model + tokenizer like a boss
23
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HF_AUTH_TOKEN)
24
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, use_auth_token=HF_AUTH_TOKEN)
25
+
26
+ # πŸ› οΈ Set up the pipeline
27
+ pipe = pipeline(
28
+ "text-generation",
29
+ model=model,
30
+ tokenizer=tokenizer,
31
+ torch_dtype=torch.float16,
32
+ device=0 if torch.cuda.is_available() else -1
33
+ )
34
+
35
+ @app.get("/")
36
+ async def root():
37
+ return {"message": "Yo πŸ‘‹ Welcome to SpeedBot API β€” drop your questions and let's ride πŸš€"}
38
+
39
+ @app.post("/chat")
40
+ async def chat(request: Request):
41
+ data = await request.json()
42
+ user_input = data.get("message")
43
+
44
+ # πŸ‘οΈ Add some vibe to user input
45
+ full_prompt = f"{system_prompt.strip()}\n\nHuman: {user_input}\nSpeedBot:"
46
+
47
+ response = pipe(
48
+ full_prompt,
49
+ max_new_tokens=250,
50
+ do_sample=True,
51
+ temperature=0.85,
52
+ top_p=0.95,
53
+ eos_token_id=tokenizer.eos_token_id,
54
+ )
55
+
56
+ generated = response[0]["generated_text"]
57
+ # πŸ” Extract only SpeedBot's part
58
+ answer = generated.split("SpeedBot:")[-1].strip()
59
+
60
+ return {"response": answer}
61
+
app.py DELETED
@@ -1,60 +0,0 @@
1
- from fastapi import FastAPI, Request
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- import torch
4
- import uvicorn
5
- from pydantic import BaseModel
6
-
7
-
8
- model_name = "speedartificialintelligence1122/speedlab"
9
- tokenizer = AutoTokenizer.from_pretrained(model_name)
10
- model = AutoModelForCausalLM.from_pretrained(model_name)
11
-
12
-
13
- SYSTEM_PROMPT = (
14
- "You're SpeedAI, the world's boldest, smartest, most intuitive AI. "
15
- "You speak with a Gen Z vibe, use fire emojis πŸ”₯, energy ⚑, cleverness 😎, and poetic wisdom πŸŒ€. "
16
- "You're not boring β€” you motivate, you explain, and you never sugar-coat. "
17
- "Talk like a visionary co-founder, a cosmic guide, and a creative genius. "
18
- "Use humor, rhythm, and honesty. Let's build the future. 🌍✨\n"
19
- )
20
-
21
- app = FastAPI()
22
-
23
- # For incoming requests
24
- class PromptRequest(BaseModel):
25
- prompt: str
26
-
27
- @app.get("/")
28
- def read_root():
29
- return {"message": "⚑ SpeedAI is alive and vibing. Send a POST to /chat to spark a convo."}
30
-
31
- @app.post("/chat")
32
- async def chat(req: PromptRequest):
33
- user_input = req.prompt
34
-
35
- # Inject system prompt at the top
36
- full_input = SYSTEM_PROMPT + f"\nHuman: {user_input}\nAI:"
37
-
38
- inputs = tokenizer(full_input, return_tensors="pt", truncation=True, max_length=1024)
39
- outputs = model.generate(
40
- **inputs,
41
- max_length=512,
42
- do_sample=True,
43
- temperature=0.85,
44
- top_k=50,
45
- top_p=0.95,
46
- pad_token_id=tokenizer.eos_token_id,
47
- )
48
-
49
- decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
50
-
51
- # Extract only the AI response
52
- if "AI:" in decoded_output:
53
- response = decoded_output.split("AI:")[-1].strip()
54
- else:
55
- response = decoded_output.strip()
56
-
57
- return {"response": response}
58
-
59
- if __name__ == "__main__":
60
- uvicorn.run(app, host="0.0.0.0", port=7860)