Spaces:
Runtime error
Runtime error
Download main.py from Subodh358/NeuralRootsAI: direct link, hf CLI and curl.
- Browser
- Download file 895 Bytes
-
https://huggingface.co/spaces/Subodh358/NeuralRootsAI/resolve/main/main.py
- Command line
-
hf download hf://spaces/Subodh358/NeuralRootsAI/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Subodh358/NeuralRootsAI/resolve/main/main.py
895 Bytes
| from fastapi import FastAPI, HTTPException | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline | |
| import os | |
| app = FastAPI() | |
| # Hugging Face authentication token | |
| hf_token = os.getenv("HF_TOKEN") | |
| # Load model and tokenizer with the authentication token | |
| model_name = "unsloth/codellama-34b-bnb-4bit" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token) | |
| model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token) | |
| generator = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| def greet_json(): | |
| return {"Hello": "World!"} | |
| def generate_text(prompt: str): | |
| try: | |
| generated_text = generator(prompt, max_length=50) | |
| return {"generated_text": generated_text[0]['generated_text']} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |