File size: 1,010 Bytes
78abc46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""6.3 hugging face - gradio.ipynb
Automatically generated by Colab.
Original file is located at
    https://colab.research.google.com/drive/1JpRdo-xi3cVH-bQtQp_mWpctxk0krUQR
"""

#from google.colab import userdata
import os
#https://console.groq.com/keys
#os.environ['GROQ_API_KEY'] = userdata.get('GROQ_API_KEY')

from groq import Groq
client = Groq()

import gradio as gr
from groq import Groq

# Define a simple function
def groq(text):
  client = Groq()
  completion = client.chat.completions.create(
      model="llama-3.1-8b-instant",
      messages=[
          {
              "role": "user",
              "content": text
          }
      ]
  )
  return(completion.choices[0].message.content)

# Create Gradio interface
demo = gr.Interface(
    fn=groq,               # Function to call
    inputs=gr.Textbox(label="Enter text", lines=12),  # Input component
    outputs=gr.Textbox(label="query", lines=12) # Output component
)

# Launch the interface
demo.launch(debug=True)