sdgzero2ai commited on
Commit
93110cc
·
verified ·
1 Parent(s): 456878c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
+
4
+ # Replace "username/llama3.3" with your actual model repository
5
+ MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf"
6
+
7
+ # Load tokenizer and model
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype="auto")
10
+
11
+ # Create a text-generation pipeline
12
+ text_gen = pipeline(
13
+ "text-generation",
14
+ model=model,
15
+ tokenizer=tokenizer,
16
+ max_length=512,
17
+ do_sample=True,
18
+ temperature=0.7
19
+ )
20
+
21
+ def chat(user_input):
22
+ """
23
+ Simple chat function that prepends user input to a system prompt (if needed)
24
+ and returns the model's text generation.
25
+ """
26
+ # If you have a special prompt format for a chat model, add it here.
27
+ # For a generic chat, you can just send the user_input:
28
+ outputs = text_gen(user_input, max_length=512)
29
+ return outputs[0]["generated_text"]
30
+
31
+ demo = gr.Interface(
32
+ fn=chat,
33
+ inputs="text",
34
+ outputs="text",
35
+ title="LLaMA3.3 Chat (Example)",
36
+ description="A chat interface for the LLaMA-based model named 'llama3.3'."
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ demo.launch()