LazyHuman10 commited on
Commit ·
553b155
1
Parent(s): 01a5f2b
fxed some bugs
Browse files- README.md +14 -2
- app.py +0 -3
- index.html +1 -1
- model_engine.py +5 -1
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -10,6 +10,13 @@ app_file: app.py
|
|
| 10 |
pinned: true
|
| 11 |
license: mit
|
| 12 |
short_description: Turn anyone into a living RPG character
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
<!--
|
|
@@ -52,12 +59,17 @@ NPCverse uses [`openbmb/MiniCPM-V-4.6`](https://huggingface.co/openbmb/MiniCPM-V
|
|
| 52 |
git clone https://huggingface.co/spaces/build-small-hackathon/NPCverse
|
| 53 |
cd NPCverse
|
| 54 |
python -m venv .venv
|
| 55 |
-
.venv\Scripts\activate
|
|
|
|
| 56 |
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
python app.py
|
| 58 |
```
|
| 59 |
|
| 60 |
-
Open `http://localhost:7860` after the server starts.
|
| 61 |
|
| 62 |
## Environment Variables
|
| 63 |
|
|
|
|
| 10 |
pinned: true
|
| 11 |
license: mit
|
| 12 |
short_description: Turn anyone into a living RPG character
|
| 13 |
+
full_width: true
|
| 14 |
+
tags:
|
| 15 |
+
- zerogpu
|
| 16 |
+
- gradio-server
|
| 17 |
+
- image-to-text
|
| 18 |
+
- rpg
|
| 19 |
+
- character-generation
|
| 20 |
---
|
| 21 |
|
| 22 |
<!--
|
|
|
|
| 59 |
git clone https://huggingface.co/spaces/build-small-hackathon/NPCverse
|
| 60 |
cd NPCverse
|
| 61 |
python -m venv .venv
|
| 62 |
+
.venv\Scripts\activate # Windows
|
| 63 |
+
# source .venv/bin/activate # macOS/Linux
|
| 64 |
pip install -r requirements.txt
|
| 65 |
+
|
| 66 |
+
# Optional: create a .env file if you hit Hub rate limits locally
|
| 67 |
+
# echo HF_TOKEN=hf_... > .env
|
| 68 |
+
|
| 69 |
python app.py
|
| 70 |
```
|
| 71 |
|
| 72 |
+
Open `http://localhost:7860` after the server starts. The model (`openbmb/MiniCPM-V-4.6`, ~3 GB) will be downloaded from the Hub on first run.
|
| 73 |
|
| 74 |
## Environment Variables
|
| 75 |
|
app.py
CHANGED
|
@@ -8,7 +8,6 @@ import json
|
|
| 8 |
import os
|
| 9 |
from typing import Any
|
| 10 |
|
| 11 |
-
import spaces
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 14 |
from gradio import Server
|
|
@@ -46,7 +45,6 @@ async def health() -> JSONResponse:
|
|
| 46 |
|
| 47 |
|
| 48 |
@app.api(name="summon_npc")
|
| 49 |
-
@spaces.GPU
|
| 50 |
def summon_npc(image_path: Any) -> dict:
|
| 51 |
"""Analyze an uploaded image and summon a complete NPC profile."""
|
| 52 |
try:
|
|
@@ -59,7 +57,6 @@ def summon_npc(image_path: Any) -> dict:
|
|
| 59 |
|
| 60 |
|
| 61 |
@app.api(name="chat_with_npc")
|
| 62 |
-
@spaces.GPU
|
| 63 |
def chat_with_npc_api(
|
| 64 |
npc_json: str,
|
| 65 |
history_json: str,
|
|
|
|
| 8 |
import os
|
| 9 |
from typing import Any
|
| 10 |
|
|
|
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 13 |
from gradio import Server
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
@app.api(name="summon_npc")
|
|
|
|
| 48 |
def summon_npc(image_path: Any) -> dict:
|
| 49 |
"""Analyze an uploaded image and summon a complete NPC profile."""
|
| 50 |
try:
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
@app.api(name="chat_with_npc")
|
|
|
|
| 60 |
def chat_with_npc_api(
|
| 61 |
npc_json: str,
|
| 62 |
history_json: str,
|
index.html
CHANGED
|
@@ -709,7 +709,7 @@
|
|
| 709 |
|
| 710 |
function getClient() {
|
| 711 |
if (!clientPromise) {
|
| 712 |
-
clientPromise = Client.connect(
|
| 713 |
}
|
| 714 |
return clientPromise;
|
| 715 |
}
|
|
|
|
| 709 |
|
| 710 |
function getClient() {
|
| 711 |
if (!clientPromise) {
|
| 712 |
+
clientPromise = Client.connect(window.location.origin);
|
| 713 |
}
|
| 714 |
return clientPromise;
|
| 715 |
}
|
model_engine.py
CHANGED
|
@@ -22,7 +22,7 @@ model = AutoModelForImageTextToText.from_pretrained(
|
|
| 22 |
MODEL_ID,
|
| 23 |
trust_remote_code=True,
|
| 24 |
dtype="auto",
|
| 25 |
-
).eval()
|
| 26 |
|
| 27 |
FRIENDSHIP_THRESHOLDS = [10, 20, 35, 55]
|
| 28 |
SECRET_THRESHOLDS = [8, 18, 35]
|
|
@@ -122,6 +122,10 @@ def _generate_from_messages(
|
|
| 122 |
downsample_mode: str = "16x",
|
| 123 |
) -> str:
|
| 124 |
"""Generate text with MiniCPM-V-4.6 from chat-template messages."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
inputs = processor.apply_chat_template(
|
| 126 |
messages,
|
| 127 |
tokenize=True,
|
|
|
|
| 22 |
MODEL_ID,
|
| 23 |
trust_remote_code=True,
|
| 24 |
dtype="auto",
|
| 25 |
+
).eval()
|
| 26 |
|
| 27 |
FRIENDSHIP_THRESHOLDS = [10, 20, 35, 55]
|
| 28 |
SECRET_THRESHOLDS = [8, 18, 35]
|
|
|
|
| 122 |
downsample_mode: str = "16x",
|
| 123 |
) -> str:
|
| 124 |
"""Generate text with MiniCPM-V-4.6 from chat-template messages."""
|
| 125 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 126 |
+
if model.device.type != device:
|
| 127 |
+
model.to(device)
|
| 128 |
+
|
| 129 |
inputs = processor.apply_chat_template(
|
| 130 |
messages,
|
| 131 |
tokenize=True,
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
gradio
|
|
|
|
| 2 |
transformers>=5.7.0
|
| 3 |
torch
|
| 4 |
torchvision
|
|
|
|
| 1 |
+
gradio==6.16.0
|
| 2 |
+
fastapi>=0.115.0
|
| 3 |
transformers>=5.7.0
|
| 4 |
torch
|
| 5 |
torchvision
|