Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,40 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
-
|
| 42 |
-
"""
|
| 43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 44 |
-
"""
|
| 45 |
-
demo = gr.ChatInterface(
|
| 46 |
-
respond,
|
| 47 |
-
additional_inputs=[
|
| 48 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 49 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 51 |
-
gr.Slider(
|
| 52 |
-
minimum=0.1,
|
| 53 |
-
maximum=1.0,
|
| 54 |
-
value=0.95,
|
| 55 |
-
step=0.05,
|
| 56 |
-
label="Top-p (nucleus sampling)",
|
| 57 |
-
),
|
| 58 |
-
],
|
| 59 |
)
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
if __name__ == "__main__":
|
| 63 |
-
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from mistralai import Mistral, UserMessage
|
| 4 |
+
from dotenv import load_dotenv, find_dotenv
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def chat_bot(user_input):
|
| 8 |
+
load_dotenv(find_dotenv())
|
| 9 |
+
miss_api_key = os.environ["MISTRAL_API"]
|
| 10 |
+
model = "mistral-small-latest"
|
| 11 |
+
|
| 12 |
+
client = Mistral(api_key=miss_api_key)
|
| 13 |
+
|
| 14 |
+
message = [{
|
| 15 |
+
"role": "user",
|
| 16 |
+
"content": user_input,
|
| 17 |
+
}, ]
|
| 18 |
+
|
| 19 |
+
chat_response = client.chat.complete(
|
| 20 |
+
model=model,
|
| 21 |
+
messages=message,
|
| 22 |
+
)
|
| 23 |
+
# response = client.create_chat_completion()
|
| 24 |
+
return chat_response.choices[0].message.content
|
| 25 |
+
|
| 26 |
+
# for chunk in client.chat.stream(model=model, messages=message):
|
| 27 |
+
# if "delta" in chunk.data.choices[0]:
|
| 28 |
+
# if chunk.data.choices[0].delta.content:
|
| 29 |
+
# print(chunk.data.choices[0].delta.content, end="")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
iface = gr.Interface(
|
| 33 |
+
fn=chat_bot,
|
| 34 |
+
inputs="text",
|
| 35 |
+
outputs="text",
|
| 36 |
+
description="Guides the website usage",
|
| 37 |
+
examples=[["How can you help me?"]],
|
| 38 |
+
title="Website Guide"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
)
|
| 40 |
+
iface.launch()
|
|
|
|
|
|
|
|
|