File size: 1,298 Bytes
0eee64a
 
 
 
 
2f16b9c
0eee64a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
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()