Ferrxni commited on
Commit
6aa2ba4
·
1 Parent(s): 2c86bdf

comment app

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -1,36 +1,36 @@
1
- import gradio as gr
2
- from mistralai.client import MistralClient, ChatMessage
3
- import os
4
- from dotenv import load_dotenv
5
 
6
- # Load environment variables
7
- load_dotenv()
8
- api_key = os.getenv('API_KEY')
9
 
10
- # Initialize Mistral client with the API key
11
- client = MistralClient(api_key=api_key)
12
 
13
- def answer_question(question):
14
- """Directly ask Mistral the question and return the answer."""
15
- # Format the user's question for Mistral
16
- user_message = question
17
 
18
- # Use the run_mistral function to get an answer
19
- answer = run_mistral(user_message)
20
 
21
- return answer
22
 
23
- def run_mistral(user_message, model="mistral-medium"):
24
- """Interact with Mistral using chat."""
25
- messages = [ChatMessage(role="user", content=user_message)]
26
- chat_response = client.chat(model=model, messages=messages)
27
- return chat_response.choices[0].message.content
28
 
29
- app = gr.Interface(fn=answer_question,
30
- inputs=gr.inputs.Textbox(lines=2, placeholder="Ask a question..."),
31
- outputs="text",
32
- title="Your Assistant",
33
- description="Ask any question, and I'll try to provide an informative answer.")
34
 
35
- if __name__ == "__main__":
36
- app.launch(share=True) # Set `share=True` to create a public link
 
1
+ # import gradio as gr
2
+ # from mistralai.client import MistralClient, ChatMessage
3
+ # import os
4
+ # from dotenv import load_dotenv
5
 
6
+ # # Load environment variables
7
+ # load_dotenv()
8
+ # api_key = os.getenv('API_KEY')
9
 
10
+ # # Initialize Mistral client with the API key
11
+ # client = MistralClient(api_key=api_key)
12
 
13
+ # def answer_question(question):
14
+ # """Directly ask Mistral the question and return the answer."""
15
+ # # Format the user's question for Mistral
16
+ # user_message = question
17
 
18
+ # # Use the run_mistral function to get an answer
19
+ # answer = run_mistral(user_message)
20
 
21
+ # return answer
22
 
23
+ # def run_mistral(user_message, model="mistral-medium"):
24
+ # """Interact with Mistral using chat."""
25
+ # messages = [ChatMessage(role="user", content=user_message)]
26
+ # chat_response = client.chat(model=model, messages=messages)
27
+ # return chat_response.choices[0].message.content
28
 
29
+ # app = gr.Interface(fn=answer_question,
30
+ # inputs=gr.inputs.Textbox(lines=2, placeholder="Ask a question..."),
31
+ # outputs="text",
32
+ # title="Your Assistant",
33
+ # description="Ask any question, and I'll try to provide an informative answer.")
34
 
35
+ # if __name__ == "__main__":
36
+ # app.launch(share=True) # Set `share=True` to create a public link