Arjun Singh commited on
Commit
10349c3
·
1 Parent(s): 2b59115
Files changed (2) hide show
  1. app.py +46 -0
  2. app_HF_Inference.py +1 -1
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from groq import Groq
3
+ import os
4
+
5
+ system_prompt = """
6
+ You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. Your response should be complete, and not end abruptly.
7
+ """
8
+
9
+ client = Groq(
10
+ api_key=os.environ.get("groq_api_key"),
11
+ )
12
+
13
+ def chat_with_Mixtral():
14
+ chat_completion = client.chat.completions.create(
15
+ messages=[{"role": "system", "content": system_prompt},{"role": "user", "content": prompt}],
16
+ model="llama-3.1-8b-instant",
17
+ )
18
+
19
+ return chat_completion.choices[0].message.content
20
+
21
+ def clear_fields():
22
+ return "", "" # Clear prompt and output, but not the API key
23
+
24
+
25
+ #demo = gr.Interface(fn=chat_with_Mixtral, inputs=[gr.Textbox(label="Question"),gr.Textbox(label="Hugging Face API Key", type="password")],outputs="text")
26
+
27
+ with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
28
+ gr.Markdown("<center><h2>Arjun's Chatbot</h2></center>")
29
+ gr.Markdown("Hi there! I'm an AI assistant tasked with answering one question at a time. I'm instructed to provide complete and truthful responses, without any harmful or biased content. I have some memory issues which are work in progress, so I cannot remember previous conversations, yet! In order to get a response, please provide your Hugging Face (HF) API Token along with your question. This token is unique for every HF user and can be found at [Access Tokens](https://huggingface.co/settings/tokens). Happy Chatting!")
30
+ prompt = gr.Textbox(label='Question', lines=2, max_lines=5, placeholder = 'Type your question here.')
31
+
32
+ with gr.Group():
33
+ with gr.Row():
34
+ submit_btn = gr.Button(value="Submit", elem_id="generate_button", variant="primary", size="sm")
35
+ clear_btn = gr.ClearButton(value="Clear Question and AI Response", elem_id="clear_button", variant="secondary", size="sm")
36
+
37
+ with gr.Row() as output:
38
+ llm_output = gr.Markdown("<center><h3>AI Response</h3></center>")
39
+
40
+
41
+ submit_btn.click(fn=chat_with_Mixtral, inputs = [prompt], outputs=[llm_output])
42
+ clear_btn.click(fn=clear_fields,outputs=[prompt,llm_output])
43
+
44
+ demo.launch()
45
+ #test comment
46
+
app_HF_Inference.py CHANGED
@@ -48,6 +48,6 @@ with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
48
  submit_btn.click(fn=chat_with_Mixtral, inputs = [prompt,token], outputs=[llm_output])
49
  clear_btn.click(fn=clear_fields,outputs=[prompt,llm_output])
50
 
51
- #demo.launch()
52
  #test comment
53
 
 
48
  submit_btn.click(fn=chat_with_Mixtral, inputs = [prompt,token], outputs=[llm_output])
49
  clear_btn.click(fn=clear_fields,outputs=[prompt,llm_output])
50
 
51
+ demo.launch()
52
  #test comment
53