boadisamson commited on
Commit
c63ab86
·
verified ·
1 Parent(s): d515ac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,17 +1,23 @@
1
  from fastapi import FastAPI
2
- # Use a pipeline as a high-level helper
3
  from transformers import pipeline
 
 
4
 
5
- pipe = pipeline("text-generation", model="meta-llama/Llama-3.1-8B-Instruct")
 
 
 
6
 
7
- app = FastAPI()
 
8
 
 
 
9
 
10
  @app.get('/')
11
  def home():
12
  return {"hello": "Geominds"}
13
 
14
-
15
  @app.get('/ask')
16
  def ask(prompt: str):
17
  result = pipe(prompt)
 
1
  from fastapi import FastAPI
 
2
  from transformers import pipeline
3
+ import os
4
+ from huggingface_hub import login
5
 
6
+ # Load the Hugging Face token from environment variables
7
+ hf_token = os.getenv("HF_TOKEN")
8
+ if hf_token:
9
+ login(token=hf_token)
10
 
11
+ # Initialize the Hugging Face pipeline
12
+ pipe = pipeline("text-generation", model="microsoft/phi-4", trust_remote_code=True)
13
 
14
+ # FastAPI app setup
15
+ app = FastAPI()
16
 
17
  @app.get('/')
18
  def home():
19
  return {"hello": "Geominds"}
20
 
 
21
  @app.get('/ask')
22
  def ask(prompt: str):
23
  result = pipe(prompt)