typesdigital commited on
Commit
eae58c2
·
verified ·
1 Parent(s): 106629e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from groq import Groq
4
+
5
+ # Initialize the GROQ client
6
+ client = Groq(
7
+ api_key=os.environ["GROQ_API_KEY"],
8
+ )
9
+
10
+ def generate_text(prompt, max_tokens=100):
11
+ chat_completion = client.chat.completions.create(
12
+ messages=[
13
+ {
14
+ "role": "user",
15
+ "content": prompt,
16
+ }
17
+ ],
18
+ model="mixtral-8x7b-32768",
19
+ max_tokens=max_tokens,
20
+ )
21
+ return chat_completion.choices[0].message.content
22
+
23
+ # Create the Gradio interface
24
+ iface = gr.Interface(
25
+ fn=generate_text,
26
+ inputs=[
27
+ gr.Textbox(lines=5, label="Enter your prompt"),
28
+ gr.Slider(minimum=10, maximum=500, value=100, step=10, label="Max Tokens")
29
+ ],
30
+ outputs=gr.Textbox(lines=10, label="Generated Text"),
31
+ title="GROQ-powered Text Generation",
32
+ description="Enter a prompt and get AI-generated text using GROQ API."
33
+ )
34
+
35
+ iface.launch()