Delete app.py
Browse files
app.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
# Load model from Hugging Face Hub (replace with your username/model name)
|
| 6 |
-
model_name = "hari7261/TechChat"
|
| 7 |
-
|
| 8 |
-
# Load tokenizer and model
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
-
model_name,
|
| 12 |
-
torch_dtype=torch.float16,
|
| 13 |
-
device_map="auto"
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# Chat function
|
| 17 |
-
def chat(prompt, max_new_tokens=200, temperature=0.7, top_p=0.9):
|
| 18 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 19 |
-
with torch.no_grad():
|
| 20 |
-
outputs = model.generate(
|
| 21 |
-
**inputs,
|
| 22 |
-
max_new_tokens=max_new_tokens,
|
| 23 |
-
temperature=temperature,
|
| 24 |
-
top_p=top_p,
|
| 25 |
-
pad_token_id=tokenizer.eos_token_id
|
| 26 |
-
)
|
| 27 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 28 |
-
|
| 29 |
-
# Gradio UI
|
| 30 |
-
with gr.Blocks() as demo:
|
| 31 |
-
gr.Markdown("# 馃挰 TechChat - Domain Chatbot")
|
| 32 |
-
gr.Markdown("Fine-tuned from Mistral-7B for technical Q&A")
|
| 33 |
-
|
| 34 |
-
with gr.Row():
|
| 35 |
-
with gr.Column(scale=3):
|
| 36 |
-
user_input = gr.Textbox(lines=3, placeholder="Ask me something technical...", label="Your Question")
|
| 37 |
-
max_tokens = gr.Slider(50, 500, value=200, step=10, label="Max New Tokens")
|
| 38 |
-
temperature = gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Temperature")
|
| 39 |
-
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p Sampling")
|
| 40 |
-
submit_btn = gr.Button("Generate Answer")
|
| 41 |
-
|
| 42 |
-
with gr.Column(scale=5):
|
| 43 |
-
output_box = gr.Textbox(label="TechChat Response")
|
| 44 |
-
|
| 45 |
-
submit_btn.click(
|
| 46 |
-
fn=chat,
|
| 47 |
-
inputs=[user_input, max_tokens, temperature, top_p],
|
| 48 |
-
outputs=output_box
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|