Spaces:
Sleeping
Sleeping
| # -*- 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) | |