Spaces:
Sleeping
Sleeping
| from groq import Groq | |
| import gradio as gr | |
| #initiale the API key | |
| api_key = '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' | |
| client = Groq(api_key=api_key) | |
| def generate_ideas(): | |
| try: | |
| chat_completion = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": "Generate for me 5 ideas for exciting web projects", | |
| } | |
| ], | |
| model="llama3-8b-8192", | |
| ) | |
| ideas = chat_completion.choices[0].message.content.strip() | |
| return ideas | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| #the front end of the page | |
| interface = gr.Interface( | |
| fn=generate_ideas, | |
| inputs=[], | |
| outputs="text", | |
| title="AI Homework, using Gradio and Groq", | |
| description="Click the button to generate your request." | |
| ) | |
| interface.launch() #run the page | |