initial commit
Browse files- README.md +7 -13
- app.py +16 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,14 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
title: Phi2 Personaforge Rag
|
| 3 |
-
emoji: 👀
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: purple
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.31.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
-
short_description: phi2 model to test personaforge rag-end
|
| 12 |
-
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Phi-2 NPC Chat (CPU)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
Simple inference demo for Microsoft Phi-2 model running on Hugging Face CPU Space.
|
| 4 |
+
Useful for prototyping RAG/NPC logic.
|
| 5 |
+
|
| 6 |
+
- Model: microsoft/phi-2
|
| 7 |
+
- Interface: Gradio
|
| 8 |
+
- Runtime: CPU (free tier)
|
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
model_id = "microsoft/phi-2"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 8 |
+
|
| 9 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 10 |
+
|
| 11 |
+
def chat(prompt):
|
| 12 |
+
result = pipe(prompt, max_new_tokens=100, temperature=0.7)
|
| 13 |
+
return result[0]["generated_text"]
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Phi-2 NPC Chat")
|
| 16 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|