HusseinEid commited on
Commit
576483d
1 Parent(s): 0871362

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from groq import Groq
3
+ import gradio as gr
4
+ import streamlit as st
5
+
6
+ client = Groq(
7
+ api_key=st.secrets["GROQ_API_KEY"],
8
+ )
9
+
10
+ system_prompt = {
11
+ "role": "system",
12
+ "content":
13
+ "You are a helpful assistant. You reply with very short answers. "
14
+ }
15
+
16
+ async def chat_groq(message, history):
17
+
18
+ messages = [system_prompt]
19
+
20
+ for msg in history:
21
+ messages.append({"role": "user", "content": str(msg[0])})
22
+ messages.append({"role": "assistant", "content": str(msg[1])})
23
+
24
+ messages.append({"role": "user", "content": str (message)})
25
+
26
+ response_content = ''
27
+
28
+ stream = client. chat.completions.create(
29
+ model="Llama3-8b-8192",
30
+ messages=messages,
31
+ max_tokens=1024,
32
+ temperature=1.2,
33
+ stream=True
34
+ )
35
+
36
+ for chunk in stream:
37
+ content = chunk.choices[0].delta.content
38
+ if content:
39
+ response_content += chunk. choices[0].delta.content
40
+ yield response_content
41
+
42
+ with gr. Blocks(fill_height=True) as demo:
43
+ gr.ChatInterface( chat_groq,
44
+ clear_btn=None,
45
+ undo_btn=None,
46
+ retry_btn=None,
47
+ )
48
+
49
+ demo.queue()
50
+ demo.launch(share=True)