Pengi5659 commited on
Commit
1e1b0d1
·
verified ·
1 Parent(s): c1e8ffa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -24
app.py CHANGED
@@ -1,28 +1,38 @@
1
  import gradio as gr
2
- import random as rd
3
- from huggingface_hub import InferenceClient
4
-
5
- client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
6
- def respond (message, history):
7
- messages = [{"role": "system", "content": "You are a chatbot who is sassy and doesnt explain an anser unless someone asks twice."}]
8
- if history:
9
- messages.extend(history)
10
- messages.append({"role": "user", "content": message})
11
- response = ""
12
- for message in client.chat_completion(
13
- messages,
14
- max_tokens=500,
15
- temperature=0.2,
16
- top_p=0.9,
17
- stream=True
18
- ):
19
- token = message.choices[0].delta.content
20
- response += token
21
- yield response
22
-
23
-
24
- chatbot = gr.ChatInterface(respond, type = "messages")
25
- chatbot.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
26
 
27
 
28
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Load the model and tokenizer
6
+ model_name = "Qwen/Qwen2.5-72B-Instruct"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
+
10
+ # Define the chat function
11
+ def chatbot(input_text):
12
+ inputs = tokenizer.encode(input_text, return_tensors="pt")
13
+ outputs = model.generate(inputs, max_length=150, num_return_sequences=1)
14
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
15
+ return response
16
+
17
+ # Define the Gradio interface
18
+ css = """
19
+ .gradio-container {
20
+ background-color: #8C9A61; /* Sage Green */
21
+ font-family: 'Times New Roman', Times, serif;
22
+ }
23
+ """
24
+
25
+ iface = gr.Interface(
26
+ fn=chatbot,
27
+ inputs=gr.Textbox(label="You:"),
28
+ outputs=gr.Textbox(label="Chatbot:"),
29
+ title="Qwen Chatbot",
30
+ description="A chatbot using the Qwen/Qwen2.5-72B-Instruct model.",
31
+ css=css
32
+ )
33
+
34
+ # Launch the interface
35
+ iface.launch()
36
 
37
 
38