jimy26 commited on
Commit
4b9966e
·
verified ·
1 Parent(s): f7cb94f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from huggingface_hub import login
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+
6
+
7
+ login(os.environ["HF_TOKEN"])
8
+ model_id = "jimy26/Sherlock_Model"
9
+
10
+ tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=True)
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ model_id,
13
+ device_map="auto",
14
+ torch_dtype="auto",
15
+ use_auth_token=True
16
+ )
17
+
18
+ def chat(prompt):
19
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
20
+ outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.7, top_p=0.9)
21
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+
23
+ gr.Interface(
24
+ fn=chat,
25
+ inputs=gr.Textbox(lines=3, placeholder="Ask Sherlock Holmes something..."),
26
+ outputs="text",
27
+ title="🕵️ Chat with Sherlock Holmes",
28
+ description="A character-based chatbot fine-tuned to act like Sherlock Holmes."
29
+ ).launch()