Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,19 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
model_id = "
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Load model
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
model_id,
|
| 12 |
-
torch_dtype=torch.float32,
|
| 13 |
device_map="cpu"
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
| 16 |
def generate_text(prompt):
|
| 17 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 18 |
|
|
@@ -21,17 +23,18 @@ def generate_text(prompt):
|
|
| 21 |
**inputs,
|
| 22 |
max_new_tokens=120,
|
| 23 |
temperature=0.7,
|
| 24 |
-
do_sample=True
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 28 |
|
| 29 |
-
# UI
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=generate_text,
|
| 32 |
inputs=gr.Textbox(lines=4, placeholder="कुछ पूछो..."),
|
| 33 |
outputs="text",
|
| 34 |
-
title="Texly AI",
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
iface.launch()
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 6 |
+
|
| 7 |
+
print("⏳ Loading TinyLlama...")
|
| 8 |
|
|
|
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 10 |
|
| 11 |
model = AutoModelForCausalLM.from_pretrained(
|
| 12 |
model_id,
|
|
|
|
| 13 |
device_map="cpu"
|
| 14 |
)
|
| 15 |
|
| 16 |
+
print("✅ Model Loaded!")
|
| 17 |
+
|
| 18 |
def generate_text(prompt):
|
| 19 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 20 |
|
|
|
|
| 23 |
**inputs,
|
| 24 |
max_new_tokens=120,
|
| 25 |
temperature=0.7,
|
| 26 |
+
do_sample=True,
|
| 27 |
+
top_p=0.9
|
| 28 |
)
|
| 29 |
|
| 30 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
|
|
|
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=generate_text,
|
| 34 |
inputs=gr.Textbox(lines=4, placeholder="कुछ पूछो..."),
|
| 35 |
outputs="text",
|
| 36 |
+
title="Texly AI (TinyLlama)",
|
| 37 |
+
description="Fast & Free AI Chatbot"
|
| 38 |
)
|
| 39 |
|
| 40 |
iface.launch()
|