khaled123 commited on
Commit
ff8ef9c
·
verified ·
1 Parent(s): 7ec7399

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Load your quantized model
6
+ model_name = "khaled123/hf"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
9
+
10
+ def chat(input_text):
11
+ inputs = tokenizer(input_text, return_tensors="pt")
12
+ outputs = model.generate(inputs["input_ids"], max_length=150, num_return_sequences=1)
13
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return response
15
+
16
+ iface = gr.Interface(fn=chat,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="Chatbot",
20
+ description="A chatbot using a quantized model")
21
+
22
+ iface.launch()