Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- __pycache__/backend.cpython-312.pyc +0 -0
- app.py +6 -2
- backend.py +10 -4
- deploy.py +4 -4
__pycache__/backend.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/backend.cpython-312.pyc and b/__pycache__/backend.cpython-312.pyc differ
|
|
|
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import requests
|
| 5 |
-
|
| 6 |
from models import MODEL_IDS
|
| 7 |
|
| 8 |
# Modal endpoint URL - set this after deploying backend.py
|
|
@@ -50,7 +49,11 @@ with gr.Blocks(title="posttraining-practice") as demo:
|
|
| 50 |
gr.Markdown("# posttraining-practice")
|
| 51 |
gr.Markdown("Chat with different fine-tuned models")
|
| 52 |
|
| 53 |
-
missing = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
if missing:
|
| 55 |
gr.Markdown(f"⚠️ **Warning:** Missing secrets: {', '.join(missing)}")
|
| 56 |
|
|
@@ -63,6 +66,7 @@ with gr.Blocks(title="posttraining-practice") as demo:
|
|
| 63 |
description=f"Chatting with: {model_id}",
|
| 64 |
)
|
| 65 |
|
|
|
|
| 66 |
def check_password(username: str, password: str) -> bool:
|
| 67 |
return password == SITE_PASSWORD
|
| 68 |
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import requests
|
|
|
|
| 5 |
from models import MODEL_IDS
|
| 6 |
|
| 7 |
# Modal endpoint URL - set this after deploying backend.py
|
|
|
|
| 49 |
gr.Markdown("# posttraining-practice")
|
| 50 |
gr.Markdown("Chat with different fine-tuned models")
|
| 51 |
|
| 52 |
+
missing = [
|
| 53 |
+
v
|
| 54 |
+
for v in ["MODAL_ENDPOINT", "MODEL_SITE_API_KEY", "SITE_PASSWORD"]
|
| 55 |
+
if not os.environ.get(v)
|
| 56 |
+
]
|
| 57 |
if missing:
|
| 58 |
gr.Markdown(f"⚠️ **Warning:** Missing secrets: {', '.join(missing)}")
|
| 59 |
|
|
|
|
| 66 |
description=f"Chatting with: {model_id}",
|
| 67 |
)
|
| 68 |
|
| 69 |
+
|
| 70 |
def check_password(username: str, password: str) -> bool:
|
| 71 |
return password == SITE_PASSWORD
|
| 72 |
|
backend.py
CHANGED
|
@@ -3,7 +3,6 @@ import os
|
|
| 3 |
|
| 4 |
import modal
|
| 5 |
from fastapi import Header
|
| 6 |
-
|
| 7 |
from models import MODEL_IDS
|
| 8 |
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -62,7 +61,9 @@ class Inference:
|
|
| 62 |
import torch
|
| 63 |
|
| 64 |
logger.info(
|
| 65 |
-
f"Received request: model_id={request.get('model_id')},
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
expected_key = os.environ.get("MODEL_SITE_API_KEY")
|
|
@@ -88,8 +89,13 @@ class Inference:
|
|
| 88 |
model = self.models[model_id]["model"]
|
| 89 |
|
| 90 |
conversation = ""
|
| 91 |
-
for
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
conversation += f"User: {message}\nAssistant:"
|
| 94 |
|
| 95 |
try:
|
|
|
|
| 3 |
|
| 4 |
import modal
|
| 5 |
from fastapi import Header
|
|
|
|
| 6 |
from models import MODEL_IDS
|
| 7 |
|
| 8 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 61 |
import torch
|
| 62 |
|
| 63 |
logger.info(
|
| 64 |
+
f"Received request: model_id={request.get('model_id')}, "
|
| 65 |
+
f"message_len={len(request.get('message', ''))}, "
|
| 66 |
+
f"history_len={len(request.get('history', []))}"
|
| 67 |
)
|
| 68 |
|
| 69 |
expected_key = os.environ.get("MODEL_SITE_API_KEY")
|
|
|
|
| 89 |
model = self.models[model_id]["model"]
|
| 90 |
|
| 91 |
conversation = ""
|
| 92 |
+
for msg in history:
|
| 93 |
+
role = msg.get("role", "user")
|
| 94 |
+
content = msg.get("content", "")
|
| 95 |
+
if role == "user":
|
| 96 |
+
conversation += f"User: {content}\n"
|
| 97 |
+
else:
|
| 98 |
+
conversation += f"Assistant: {content}\n"
|
| 99 |
conversation += f"User: {message}\nAssistant:"
|
| 100 |
|
| 101 |
try:
|
deploy.py
CHANGED
|
@@ -7,7 +7,7 @@ import subprocess
|
|
| 7 |
import sys
|
| 8 |
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
-
from huggingface_hub import HfApi
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
|
|
@@ -17,7 +17,7 @@ SPACE_TITLE = "posttraining-practice"
|
|
| 17 |
def main():
|
| 18 |
api_key = os.environ.get("MODEL_SITE_API_KEY")
|
| 19 |
site_password = os.environ.get("SITE_PASSWORD")
|
| 20 |
-
if
|
| 21 |
sys.exit("ERROR: MODEL_SITE_API_KEY and SITE_PASSWORD must be set in .env")
|
| 22 |
|
| 23 |
api = HfApi()
|
|
@@ -34,7 +34,7 @@ def main():
|
|
| 34 |
print(result.stdout + result.stderr)
|
| 35 |
|
| 36 |
match = re.search(r"https://[^\s]+\.modal\.run", result.stdout + result.stderr)
|
| 37 |
-
if
|
| 38 |
sys.exit("ERROR: Could not find Modal endpoint URL")
|
| 39 |
modal_endpoint = match.group(0)
|
| 40 |
|
|
@@ -53,7 +53,7 @@ def main():
|
|
| 53 |
repo_id=space_id,
|
| 54 |
repo_type="space",
|
| 55 |
space_sdk="gradio",
|
| 56 |
-
space_hardware=
|
| 57 |
exist_ok=True,
|
| 58 |
)
|
| 59 |
|
|
|
|
| 7 |
import sys
|
| 8 |
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
+
from huggingface_hub import HfApi, SpaceHardware
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
|
|
|
|
| 17 |
def main():
|
| 18 |
api_key = os.environ.get("MODEL_SITE_API_KEY")
|
| 19 |
site_password = os.environ.get("SITE_PASSWORD")
|
| 20 |
+
if api_key is None or site_password is None:
|
| 21 |
sys.exit("ERROR: MODEL_SITE_API_KEY and SITE_PASSWORD must be set in .env")
|
| 22 |
|
| 23 |
api = HfApi()
|
|
|
|
| 34 |
print(result.stdout + result.stderr)
|
| 35 |
|
| 36 |
match = re.search(r"https://[^\s]+\.modal\.run", result.stdout + result.stderr)
|
| 37 |
+
if match is None:
|
| 38 |
sys.exit("ERROR: Could not find Modal endpoint URL")
|
| 39 |
modal_endpoint = match.group(0)
|
| 40 |
|
|
|
|
| 53 |
repo_id=space_id,
|
| 54 |
repo_type="space",
|
| 55 |
space_sdk="gradio",
|
| 56 |
+
space_hardware=SpaceHardware.CPU_BASIC,
|
| 57 |
exist_ok=True,
|
| 58 |
)
|
| 59 |
|