Spaces:
Running
Running
new model
Browse files- Dockerfile.txt +2 -0
- app.py +17 -13
- requirements.txt +1 -0
Dockerfile.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.10
|
| 2 |
|
| 3 |
# Prevent Python from writing .pyc files / enable unbuffered logs
|
|
|
|
| 1 |
+
#dockerfile.txt
|
| 2 |
+
|
| 3 |
FROM python:3.10
|
| 4 |
|
| 5 |
# Prevent Python from writing .pyc files / enable unbuffered logs
|
app.py
CHANGED
|
@@ -14,7 +14,14 @@ from tensorflow import keras
|
|
| 14 |
from PIL import Image
|
| 15 |
|
| 16 |
import tenacity
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# --- LangChain v0.2 family ---
|
| 20 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
@@ -41,7 +48,7 @@ from pydantic import BaseModel, Field # <-- switched to Pydantic v2
|
|
| 41 |
from huggingface_hub import snapshot_download
|
| 42 |
|
| 43 |
# === LLM endpoint moderno (compatible con huggingface_hub>=0.23) ===
|
| 44 |
-
from langchain_huggingface import HuggingFaceEndpoint
|
| 45 |
|
| 46 |
# Theming + URL list
|
| 47 |
import theme
|
|
@@ -97,8 +104,6 @@ image_gradio_app = gr.Interface(
|
|
| 97 |
# ============================================
|
| 98 |
# 2) KNOWLEDGE LOADING (RAG: loader + splitter)
|
| 99 |
# ============================================
|
| 100 |
-
user_agent = UserAgent().random
|
| 101 |
-
header_template = {"User-Agent": user_agent}
|
| 102 |
|
| 103 |
@tenacity.retry(wait=tenacity.wait_fixed(3), stop=tenacity.stop_after_attempt(3), reraise=True)
|
| 104 |
def load_url(url: str):
|
|
@@ -179,26 +184,25 @@ qa_prompt = ChatPromptTemplate.from_template(
|
|
| 179 |
)
|
| 180 |
|
| 181 |
|
|
|
|
| 182 |
# =============================
|
| 183 |
-
# 4) LLM — Hugging Face Inference API (
|
| 184 |
# =============================
|
| 185 |
-
|
| 186 |
-
llm = HuggingFaceEndpoint(
|
| 187 |
repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
|
| 188 |
-
task="conversational",
|
| 189 |
-
# estos parámetros VAN afuera de model_kwargs:
|
| 190 |
max_new_tokens=2000,
|
| 191 |
temperature=0.1,
|
| 192 |
top_k=30,
|
| 193 |
repetition_penalty=1.03,
|
| 194 |
return_full_text=False,
|
| 195 |
-
# token del Space
|
| 196 |
huggingfacehub_api_token=os.getenv("HUGGINGFACEHUB_API_TOKEN"),
|
| 197 |
-
timeout=120,
|
| 198 |
-
|
| 199 |
-
model_kwargs={},
|
| 200 |
)
|
| 201 |
|
|
|
|
|
|
|
| 202 |
|
| 203 |
# ===========================================
|
| 204 |
# 5) Chain (memory + robust JSON extraction)
|
|
|
|
| 14 |
from PIL import Image
|
| 15 |
|
| 16 |
import tenacity
|
| 17 |
+
try:
|
| 18 |
+
from fake_useragent import UserAgent
|
| 19 |
+
user_agent = UserAgent().random
|
| 20 |
+
except Exception:
|
| 21 |
+
user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "\
|
| 22 |
+
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
| 23 |
+
header_template = {"User-Agent": user_agent}
|
| 24 |
+
|
| 25 |
|
| 26 |
# --- LangChain v0.2 family ---
|
| 27 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
|
|
| 48 |
from huggingface_hub import snapshot_download
|
| 49 |
|
| 50 |
# === LLM endpoint moderno (compatible con huggingface_hub>=0.23) ===
|
| 51 |
+
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
| 52 |
|
| 53 |
# Theming + URL list
|
| 54 |
import theme
|
|
|
|
| 104 |
# ============================================
|
| 105 |
# 2) KNOWLEDGE LOADING (RAG: loader + splitter)
|
| 106 |
# ============================================
|
|
|
|
|
|
|
| 107 |
|
| 108 |
@tenacity.retry(wait=tenacity.wait_fixed(3), stop=tenacity.stop_after_attempt(3), reraise=True)
|
| 109 |
def load_url(url: str):
|
|
|
|
| 184 |
)
|
| 185 |
|
| 186 |
|
| 187 |
+
|
| 188 |
# =============================
|
| 189 |
+
# 4) LLM — Hugging Face Inference API (Llama 3 chat)
|
| 190 |
# =============================
|
| 191 |
+
endpoint = HuggingFaceEndpoint(
|
|
|
|
| 192 |
repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
|
| 193 |
+
task="conversational",
|
|
|
|
| 194 |
max_new_tokens=2000,
|
| 195 |
temperature=0.1,
|
| 196 |
top_k=30,
|
| 197 |
repetition_penalty=1.03,
|
| 198 |
return_full_text=False,
|
|
|
|
| 199 |
huggingfacehub_api_token=os.getenv("HUGGINGFACEHUB_API_TOKEN"),
|
| 200 |
+
timeout=120,
|
| 201 |
+
model_kwargs={},
|
|
|
|
| 202 |
)
|
| 203 |
|
| 204 |
+
# Usa el wrapper de modelo de **chat**
|
| 205 |
+
llm = ChatHuggingFace(client=endpoint)
|
| 206 |
|
| 207 |
# ===========================================
|
| 208 |
# 5) Chain (memory + robust JSON extraction)
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
# Core
|
| 2 |
transformers>=4.42.0
|
| 3 |
torch
|
|
|
|
| 1 |
+
# requirements.txt
|
| 2 |
# Core
|
| 3 |
transformers>=4.42.0
|
| 4 |
torch
|