Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
model_id = "yuvrajpant56/Mistral_Posttrain_SFT"
|
| 6 |
-
|
| 7 |
-
# Load model & tokenizer
|
| 8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 10 |
|
| 11 |
def generate_text(prompt):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
gr.Interface(
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
model_id = "yuvrajpant56/Mistral_Posttrain_SFT"
|
| 5 |
+
client = InferenceClient(model_id)
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def generate_text(prompt):
|
| 8 |
+
response = ""
|
| 9 |
+
for token in client.text_generation(prompt, stream=True, max_new_tokens=100):
|
| 10 |
+
response += token.token
|
| 11 |
+
return response
|
| 12 |
|
| 13 |
+
gr.Interface(
|
| 14 |
+
fn=generate_text,
|
| 15 |
+
inputs="text",
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Mistral SFT Text Generator",
|
| 18 |
+
description="Type a prompt and let the fine-tuned Mistral model generate the rest."
|
| 19 |
).launch()
|