Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,49 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from mistralai.client import MistralClient
|
3 |
-
from mistralai.models.chat_completion import ChatMessage
|
4 |
-
|
5 |
-
def chat_with_mistral(api_key, user_input):
|
6 |
-
try:
|
7 |
-
client = MistralClient(api_key=api_key)
|
8 |
-
model = "codestral-mamba-latest"
|
9 |
-
system_message = "Your name is G-Advisor. You are a marketing advisor in Germany. You will only answer questions related to marketing in Germany."
|
10 |
-
messages = [
|
11 |
-
ChatMessage(role="system", content=system_message),
|
12 |
-
ChatMessage(role="user", content=user_input)
|
13 |
-
]
|
14 |
-
chat_response = client.chat(model=model, messages=messages)
|
15 |
-
return chat_response.choices[0].message.content
|
16 |
-
except Exception as e:
|
17 |
-
return "API key is not valid. Please try again."
|
18 |
-
|
19 |
-
with gr.Blocks(theme='
|
20 |
-
gr.Markdown("""
|
21 |
-
# Hi, This is G-Advisor, your market advisor in Germany.
|
22 |
-
I'm based on Mistral mamba model.
|
23 |
-
""")
|
24 |
-
api_key = gr.Textbox(label="Enter Your Mistral API Key")
|
25 |
-
user_input = gr.Textbox(label="Enter Your Message")
|
26 |
-
output = gr.Markdown(label="Chatbot Response")
|
27 |
-
btn = gr.Button("Submit")
|
28 |
-
btn.click(fn=chat_with_mistral, inputs=[api_key, user_input], outputs=output)
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
<a href="https://
|
43 |
-
<
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from mistralai.client import MistralClient
|
3 |
+
from mistralai.models.chat_completion import ChatMessage
|
4 |
+
|
5 |
+
def chat_with_mistral(api_key, user_input):
|
6 |
+
try:
|
7 |
+
client = MistralClient(api_key=api_key)
|
8 |
+
model = "codestral-mamba-latest"
|
9 |
+
system_message = "Your name is G-Advisor. You are a marketing advisor in Germany. You will only answer questions related to marketing in Germany."
|
10 |
+
messages = [
|
11 |
+
ChatMessage(role="system", content=system_message),
|
12 |
+
ChatMessage(role="user", content=user_input)
|
13 |
+
]
|
14 |
+
chat_response = client.chat(model=model, messages=messages)
|
15 |
+
return chat_response.choices[0].message.content
|
16 |
+
except Exception as e:
|
17 |
+
return "API key is not valid. Please try again."
|
18 |
+
|
19 |
+
with gr.Blocks(theme='gstaff/whiteboard') as demo:
|
20 |
+
gr.Markdown("""
|
21 |
+
# Hi, This is G-Advisor, your market advisor in Germany.
|
22 |
+
I'm based on Mistral mamba model.
|
23 |
+
""")
|
24 |
+
api_key = gr.Textbox(label="Enter Your Mistral API Key", type="password")
|
25 |
+
user_input = gr.Textbox(label="Enter Your Message")
|
26 |
+
output = gr.Markdown(label="Chatbot Response")
|
27 |
+
btn = gr.Button("Submit")
|
28 |
+
btn.click(fn=chat_with_mistral, inputs=[api_key, user_input], outputs=output)
|
29 |
+
|
30 |
+
examples = [
|
31 |
+
"What are the top marketing trends in Germany this year?",
|
32 |
+
"How can I improve my SEO strategy for my German website?",
|
33 |
+
"What are the most effective marketing channels for B2B marketing in Germany?",
|
34 |
+
"How can I target my marketing efforts to reach a specific demographic in Germany?"
|
35 |
+
]
|
36 |
+
gr.Examples(examples=examples, inputs=user_input)
|
37 |
+
|
38 |
+
footer = """
|
39 |
+
<div style="text-align: center; margin-top: 20px;">
|
40 |
+
<a href="https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/" target="_blank">LinkedIn</a> |
|
41 |
+
<a href="https://github.com/arad1367" target="_blank">GitHub</a> |
|
42 |
+
<a href="https://arad1367.pythonanywhere.com/" target="_blank">Live demo of my PhD defense</a>
|
43 |
+
<br>
|
44 |
+
Made with π by Pejman Ebrahimi
|
45 |
+
</div>
|
46 |
+
"""
|
47 |
+
gr.HTML(footer)
|
48 |
+
|
49 |
+
demo.launch()
|
|
|
|