Goekdeniz-Guelmez commited on
Commit
fb1f1d4
1 Parent(s): 502ca38

Add application file

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, pipeline
3
+ import torch
4
+
5
+ # Initialize the model and tokenizer
6
+ model = "Isaak-Carter/JOSIE_Beta-5-7B-slerp"
7
+ tokenizer = AutoTokenizer.from_pretrained(model)
8
+
9
+ ai_pipeline = transformers.pipeline(
10
+ "text-generation",
11
+ model=model_name,
12
+ torch_dtype=torch.float16,
13
+ device_map="auto",
14
+ )
15
+
16
+ def generate_response(user_input):
17
+ """
18
+ Generate a response to the user input using the specified AI model.
19
+
20
+ Args:
21
+ user_input (str): The question or prompt from the user.
22
+
23
+ Returns:
24
+ str: The generated response from the AI model.
25
+ """
26
+ messages = [{"role": "user", "content": user_input}]
27
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
28
+
29
+ pipeline = transformers.pipeline(
30
+ "text-generation",
31
+ model=model,
32
+ torch_dtype=torch.float16,
33
+ device_map="auto",
34
+ )
35
+
36
+ outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
37
+
38
+ return outputs[0]["generated_text"]
39
+
40
+ # Create Gradio interface
41
+ interface = gr.Interface(fn=generate_response, inputs="text", outputs="text", title="JOSIE Beta 5", description="Asc JOSIE Beta 5.")
42
+ interface.launch()
43
+