Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,23 @@
|
|
| 1 |
-
from
|
| 2 |
-
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
prompt
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
model_name = "your-username/your-model-name" # Replace with your actual model repo
|
| 6 |
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
+
def chat_with_ai(prompt, history=[]):
|
| 11 |
+
input_ids = tokenizer.encode(prompt + tokenizer.eos_token, return_tensors="pt")
|
| 12 |
+
output_ids = model.generate(
|
| 13 |
+
input_ids,
|
| 14 |
+
max_length=100,
|
| 15 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 16 |
+
do_sample=True,
|
| 17 |
+
top_p=0.95,
|
| 18 |
+
top_k=50
|
| 19 |
+
)
|
| 20 |
+
response = tokenizer.decode(output_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 21 |
+
return response
|
| 22 |
|
| 23 |
+
gr.ChatInterface(fn=chat_with_ai, title="SpeedAI Assistant").launch()
|