SarmaHighOnAI commited on
Commit
516c24b
·
verified ·
1 Parent(s): de19456

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -1,22 +1,24 @@
 
1
  from fastapi import FastAPI
2
- import subprocess
3
- import sys
4
 
5
  app = FastAPI()
 
 
 
 
6
 
7
  @app.get("/")
8
  def home():
9
- # This forces the server to list all installed packages
10
- # Check your "Logs" tab after visiting this page!
11
- result = subprocess.run([sys.executable, "-m", "pip", "freeze"], capture_output=True, text=True)
12
- print("=== INSTALLED PACKAGES ===")
13
- print(result.stdout)
14
- print("==========================")
15
-
16
- try:
17
- import llama_cpp
18
- status = "llama_cpp is INSTALLED!"
19
- except ImportError as e:
20
- status = f"CRITICAL ERROR: {e}"
21
-
22
- return {"status": status, "packages_printed_to_logs": True}
 
1
+ import os
2
  from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ from huggingface_hub import InferenceClient
5
 
6
  app = FastAPI()
7
+ client = InferenceClient(api_key=os.environ.get("HF_TOKEN"))
8
+
9
+ class Request(BaseModel):
10
+ prompt: str
11
 
12
  @app.get("/")
13
  def home():
14
+ return {"status": "Running"}
15
+
16
+ @app.post("/generate")
17
+ def generate_text(request: Request):
18
+ messages = [{"role": "user", "content": request.prompt}]
19
+ response = client.chat_completion(
20
+ messages=messages,
21
+ model="HuggingFaceTB/SmolLM2-1.7B-Instruct",
22
+ max_tokens=500
23
+ )
24
+ return {"response": response.choices[0].message.content}