ZPRIA commited on
Commit
e163068
·
verified ·
1 Parent(s): c006134

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -1,25 +1,31 @@
1
- # app.py — এই কোডটা Space-এ দাও
2
- import gradio as gr
3
  from transformers import pipeline
 
 
 
4
 
5
- # ছোট AI মডেল (CPU-তে চলে)
 
 
6
  generator = pipeline(
7
  "text-generation",
8
- model="facebook/opt-125m", # 125MB — দ্রুত লোড হয়
9
- max_new_tokens=150
10
  )
11
 
12
- def chat(message):
13
- result = generator(message, do_sample=True, temperature=0.7)
14
- return result[0]['generated_text']
15
 
16
- # Gradio UI + API
17
- demo = gr.Interface(
18
- fn=chat,
19
- inputs=gr.Textbox(placeholder="প্রশ্ন লেখো..."),
20
- outputs=gr.Textbox(),
21
- title="আমার AI Chatbot",
22
- description="ফ্রি AI — Hugging Face দিয়ে"
23
- )
 
 
 
 
24
 
25
- demo.launch()
 
 
 
1
  from transformers import pipeline
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ import uvicorn
5
 
6
+ app = FastAPI()
7
+
8
+ # Model load (once)
9
  generator = pipeline(
10
  "text-generation",
11
+ model="TinyLlama/TinyLlama-1.1B-Chat",
12
+ device_map="cpu"
13
  )
14
 
15
+ class Request(BaseModel):
16
+ message: str
 
17
 
18
+ @app.post("/chat")
19
+ def chat(req: Request):
20
+ output = generator(
21
+ req.message,
22
+ max_new_tokens=120,
23
+ do_sample=True,
24
+ temperature=0.7
25
+ )
26
+
27
+ return {
28
+ "reply": output[0]["generated_text"]
29
+ }
30
 
31
+ # HF Spaces-এ এটা auto run হয়