import os from groq import Groq import gradio as gr # Set your API key os.environ["GROQ_API_KEY"] = "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" # Initialize the client client = Groq(api_key=os.environ.get("GROQ_API_KEY")) # Function to process document and prompt def process_document(prompt, document): # Combine the prompt and document input_text = f"{prompt}\n\n{document}" # Call the Groq API try: chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": input_text}], model="llama3-8b-8192", # Replace with the model name you want to use stream=False, ) # Extract and return the result return chat_completion.choices[0].message.content except Exception as e: return f"An error occurred: {e}" # Create the Gradio interface interface = gr.Interface( fn=process_document, inputs=[ gr.Textbox(lines=2, placeholder="Enter your prompt here", label="Prompt"), gr.Textbox(lines=10, placeholder="Paste your document here", label="Document"), ], outputs="text", title="Groq Document Processor", description="Input a prompt and a document to process using the Groq API.", ) # Launch the app interface.launch()