GIGAParviz commited on
Commit
e5c89c7
·
verified ·
1 Parent(s): d118a29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -32
app.py CHANGED
@@ -1,44 +1,30 @@
1
  import gradio as gr
2
- from unsloth import FastLanguageModel
3
- import torch
4
- from transformers import TextStreamer
5
 
6
- model, tokenizer = FastLanguageModel.from_pretrained(
7
- model_name = "unsloth/llama-2-7b-bnb-4bit",
8
- max_seq_length = 2048,
9
- dtype = torch.float16,
10
- load_in_4bit = True,
11
- ).to("cpu")
12
- FastLanguageModel.for_inference(model)
13
 
14
- def predict(input_text):
15
- messages = [
16
- {"from": "human", "value": input_text},
17
- ]
18
- inputs = tokenizer.apply_chat_template(
19
- messages,
20
- tokenize=True,
21
- add_generation_prompt=True,
22
- return_tensors="pt",
23
- ).to("cpu")
24
 
25
- outputs = model.generate(
26
- input_ids=inputs,
27
- max_new_tokens=128,
28
- use_cache=True
 
 
 
 
 
29
  )
30
-
31
- decoded_output = tokenizer.batch_decode(outputs, skip_special_tokens=True)
32
- assistant_response = decoded_output[0].split('assistant\n')[-1].strip()
33
-
34
- return assistant_response
35
 
36
  iface = gr.Interface(
37
- fn=predict,
38
  inputs="text",
39
  outputs="text",
40
- title="Parviz(eng) Chatbot",
41
- description="LLM Test model .",
42
  )
43
 
44
  iface.launch()
 
1
  import gradio as gr
2
+ from groq import Groq
 
 
3
 
 
 
 
 
 
 
 
4
 
5
+ client = Groq(
6
+ api_key=("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"),
7
+ )
8
+
 
 
 
 
 
 
9
 
10
+ def generate_response(input_text):
11
+ chat_completion = client.chat.completions.create(
12
+ messages=[
13
+ {
14
+ "role": "user",
15
+ "content": input_text,
16
+ }
17
+ ],
18
+ model="llama3-8b-8192",
19
  )
20
+ return chat_completion.choices[0].message.content
 
 
 
 
21
 
22
  iface = gr.Interface(
23
+ fn=generate_response,
24
  inputs="text",
25
  outputs="text",
26
+ title="Parviz Chatbot",
27
+ description="ye chi bepors",
28
  )
29
 
30
  iface.launch()