Zubiiiiiii294 commited on
Commit
c43025c
Β·
verified Β·
1 Parent(s): 728ab04

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -52
app.py DELETED
@@ -1,52 +0,0 @@
1
- import os
2
- import gradio as gr
3
- from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
4
- import torch
5
-
6
- # Load model from environment variable or fallback
7
- model_id = os.getenv("MODEL_ID", "TheBloke/Mistral-7B-Instruct-v0.3-GPTQ")
8
-
9
- # Load tokenizer and model
10
- tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)
11
- model = AutoModelForCausalLM.from_pretrained(
12
- model_id,
13
- device_map="auto",
14
- torch_dtype=torch.float16,
15
- )
16
-
17
- # Initialize streamer for live output
18
- streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
19
-
20
- # Define the chat function
21
- def chat(message, history):
22
- history = history or []
23
- conversation = history + [(message, "")]
24
-
25
- prompt = tokenizer.apply_chat_template(
26
- conversation,
27
- tokenize=False,
28
- add_generation_prompt=True
29
- )
30
-
31
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
32
-
33
- with torch.no_grad():
34
- output_ids = model.generate(
35
- **inputs,
36
- max_new_tokens=512,
37
- do_sample=True,
38
- temperature=0.7,
39
- top_p=0.95,
40
- )
41
-
42
- decoded = tokenizer.decode(output_ids[0], skip_special_tokens=True)
43
- reply = decoded.split(message)[-1].strip()
44
-
45
- return reply
46
-
47
- # Build Gradio UI
48
- interface = gr.ChatInterface(fn=chat, title="🧠 Vynix AI")
49
-
50
- # Launch App
51
- if _name_ == "_main_":
52
- interface.launch()