Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
model_name = "hari7261/TechChat"
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
| 7 |
+
|
| 8 |
+
def chat(prompt, max_new_tokens=150):
|
| 9 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 10 |
+
outputs = model.generate(**inputs, max_new_tokens=max_new_tokens)
|
| 11 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=chat,
|
| 15 |
+
inputs=[
|
| 16 |
+
gr.Textbox(label="Your Question"),
|
| 17 |
+
gr.Slider(50, 500, value=150, step=10, label="Max New Tokens")
|
| 18 |
+
],
|
| 19 |
+
outputs="text",
|
| 20 |
+
title="TechChat - Domain Specific Chatbot"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
iface.launch()
|