Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
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 |
-
|
15 |
-
|
16 |
-
|
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 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
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=
|
38 |
inputs="text",
|
39 |
outputs="text",
|
40 |
-
title="Parviz
|
41 |
-
description="
|
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()
|