Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
pipe = pipeline(
|
7 |
+
"text-generation",
|
8 |
+
model="google/gemma-3-1b-it",
|
9 |
+
device="cpu",
|
10 |
+
max_new_tokens=256,
|
11 |
+
temperature=0.7
|
12 |
+
)
|
13 |
+
|
14 |
+
@app.post("/generate")
|
15 |
+
async def generate(request: Request):
|
16 |
+
data = await request.json()
|
17 |
+
prompt = data.get("prompt", "")
|
18 |
+
result = pipe(prompt)
|
19 |
+
return {"response": result[0]["generated_text"]}
|