Instructions to use amogaddy/GenerAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use amogaddy/GenerAI with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="amogaddy/GenerAI")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("amogaddy/GenerAI", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use amogaddy/GenerAI with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "amogaddy/GenerAI" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amogaddy/GenerAI", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/amogaddy/GenerAI
- SGLang
How to use amogaddy/GenerAI with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "amogaddy/GenerAI" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amogaddy/GenerAI", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "amogaddy/GenerAI" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amogaddy/GenerAI", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use amogaddy/GenerAI with Docker Model Runner:
docker model run hf.co/amogaddy/GenerAI
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import uvicorn
|
| 4 |
+
from scraper import search_and_extract
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Carichiamo il modello GenerAI
|
| 9 |
+
print("Caricamento modello amogaddy/GenerAI...")
|
| 10 |
+
generator = pipeline("text-generation", model="amogaddy/GenerAI")
|
| 11 |
+
|
| 12 |
+
@app.get("/")
|
| 13 |
+
def health_check():
|
| 14 |
+
"""Endpoint di health‑check."""
|
| 15 |
+
return {"status": "running", "model": "GenerAI"}
|
| 16 |
+
|
| 17 |
+
@app.post("/ask")
|
| 18 |
+
def ask(prompt: str):
|
| 19 |
+
"""Endpoint principale per la generazione di testo con ricerca web (RAG)."""
|
| 20 |
+
# 1. Ricerca sul web per usare internet come database
|
| 21 |
+
web_results = search_and_extract(prompt, max_results=2)
|
| 22 |
+
|
| 23 |
+
context = ""
|
| 24 |
+
sources = []
|
| 25 |
+
if web_results:
|
| 26 |
+
for r in web_results:
|
| 27 |
+
context += f"Fonte [{r['title']}]: {r['text'][:500]}\n"
|
| 28 |
+
sources.append(r['url'])
|
| 29 |
+
|
| 30 |
+
# 2. Creazione del prompt finale con il contesto trovato su internet
|
| 31 |
+
if context:
|
| 32 |
+
final_prompt = f"Contesto trovato su internet:\n{context}\n\nRispondi alla seguente domanda in base al contesto: {prompt}"
|
| 33 |
+
else:
|
| 34 |
+
final_prompt = prompt
|
| 35 |
+
|
| 36 |
+
# 3. Generazione della risposta tramite il modello
|
| 37 |
+
output = generator(final_prompt, max_length=512, num_return_sequences=1)
|
| 38 |
+
answer = output[0]["generated_text"]
|
| 39 |
+
|
| 40 |
+
# 4. Rimuoviamo la parte del prompt per restituire solo la risposta generata
|
| 41 |
+
if final_prompt in answer:
|
| 42 |
+
answer = answer.replace(final_prompt, "").strip()
|
| 43 |
+
|
| 44 |
+
return {
|
| 45 |
+
"result": answer,
|
| 46 |
+
"sources": sources
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|