Spaces:
Sleeping
Sleeping
Commit
·
b079a26
1
Parent(s):
c208d16
App file added
Browse files- app.py +34 -0
- requirements.txt +11 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
from huggingface_hub import login
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
login(
|
| 8 |
+
token = os.getenv("HF_TOKEN"),
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 12 |
+
|
| 13 |
+
print("\n\nDownloading model...\n\n")
|
| 14 |
+
pipe = pipeline("text-generation", model=model_id, torch_dtype=torch.bfloat16)
|
| 15 |
+
print("\n\nModel Initialized successfully!!\n\n")
|
| 16 |
+
|
| 17 |
+
def interact(message: str, history: list):
|
| 18 |
+
chat_history = [msg for msg in history]
|
| 19 |
+
chat_history.append({
|
| 20 |
+
"role":"user",
|
| 21 |
+
"content": message
|
| 22 |
+
})
|
| 23 |
+
|
| 24 |
+
response = pipe(chat_history)
|
| 25 |
+
print("\n\nResponse: ",response, end="\n\n")
|
| 26 |
+
return response[0]["generated_text"][-1]["content"]
|
| 27 |
+
|
| 28 |
+
interface = gr.ChatInterface(
|
| 29 |
+
fn=interact,
|
| 30 |
+
type="messages",
|
| 31 |
+
title="Mistral Model Interface"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
|
| 5 |
+
tiktoken
|
| 6 |
+
blobfile
|
| 7 |
+
sentencepiece
|
| 8 |
+
einops
|
| 9 |
+
accelerate
|
| 10 |
+
fastapi
|
| 11 |
+
uvicorn
|