Spaces:
Runtime error
Runtime error
Update app.py
#1
by
alex-abb
- opened
app.py
CHANGED
@@ -1,73 +1,13 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
import spaces
|
4 |
-
import transformers
|
5 |
-
from transformers import pipeline
|
6 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# Load model directly
|
14 |
-
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained("MTSAIR/MultiVerse_70B")
|
16 |
-
model = AutoModelForCausalLM.from_pretrained("MTSAIR/MultiVerse_70B")
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
def respond(
|
21 |
-
message,
|
22 |
-
history: list[tuple[str, str]],
|
23 |
-
system_message,
|
24 |
-
max_tokens,
|
25 |
-
temperature,
|
26 |
-
top_p,
|
27 |
-
):
|
28 |
-
messages = [{"role": "system", "content": system_message}]
|
29 |
-
|
30 |
-
for val in history:
|
31 |
-
if val[0]:
|
32 |
-
messages.append({"role": "user", "content": val[0]})
|
33 |
-
if val[1]:
|
34 |
-
messages.append({"role": "assistant", "content": val[1]})
|
35 |
-
|
36 |
-
messages.append({"role": "user", "content": message})
|
37 |
-
|
38 |
-
response = ""
|
39 |
-
|
40 |
-
for message in client.chat_completion(
|
41 |
-
messages,
|
42 |
-
max_tokens=max_tokens,
|
43 |
-
stream=True,
|
44 |
-
temperature=temperature,
|
45 |
-
top_p=top_p,
|
46 |
-
):
|
47 |
-
token = message.choices[0].delta.content
|
48 |
-
|
49 |
-
response += token
|
50 |
-
yield response
|
51 |
-
|
52 |
-
"""
|
53 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
54 |
-
"""
|
55 |
-
demo = gr.ChatInterface(
|
56 |
-
respond,
|
57 |
-
additional_inputs=[
|
58 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
59 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
60 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
61 |
-
gr.Slider(
|
62 |
-
minimum=0.1,
|
63 |
-
maximum=1.0,
|
64 |
-
value=0.95,
|
65 |
-
step=0.05,
|
66 |
-
label="Top-p (nucleus sampling)",
|
67 |
-
),
|
68 |
-
],
|
69 |
-
)
|
70 |
-
|
71 |
-
|
72 |
-
if __name__ == "__main__":
|
73 |
-
demo.launch()
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Charger le modèle pour la génération de texte
|
5 |
+
pipe = pipeline("text-generation", model="MTSAIR/MultiVerse_70B")
|
6 |
|
7 |
+
# Fonction pour générer une réponse à partir du message de l'utilisateur
|
8 |
+
def generate_response(message):
|
9 |
+
response = pipe(message)
|
10 |
+
return response[0]['generated_text']
|
11 |
|
12 |
+
# Configurer et lancer l'interface de chat avec Gradio
|
13 |
+
gr.ChatInterface(fn=generate_response).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|