| | import os |
| | from groq import Groq |
| | import gradio as gr |
| |
|
| | |
| | os.environ["GROQ_API_KEY"] = "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" |
| |
|
| | |
| | client = Groq(api_key=os.environ.get("GROQ_API_KEY")) |
| |
|
| | |
| | def process_document(prompt, document): |
| | |
| | input_text = f"{prompt}\n\n{document}" |
| | |
| | |
| | try: |
| | chat_completion = client.chat.completions.create( |
| | messages=[{"role": "user", "content": input_text}], |
| | model="llama3-8b-8192", |
| | stream=False, |
| | ) |
| | |
| | return chat_completion.choices[0].message.content |
| | except Exception as e: |
| | return f"An error occurred: {e}" |
| |
|
| | |
| | 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.", |
| | ) |
| |
|
| | |
| | interface.launch() |
| |
|
| |
|