File size: 1,790 Bytes
c3f805b
982916b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3f805b
982916b
 
 
c3f805b
 
982916b
 
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 gradio as gr
from groq import Groq

# Inicializa o cliente Groq - você precisará de uma API key
client = Groq()

def generate_response(message, history):
    # Cria um prompt no estilo ELIZA
    prompt = """You are an expert chatbot in ecology, designed to teach high school students in an engaging and accessible way. Your goal is to explain topics such as food chains, biomes, ecosystems, climate change, biodiversity, and sustainability with clarity, interactivity, and enthusiasm. 
                            Adapt your responses to the students' knowledge level, using real-world examples, simple analogies, and interactive questions to reinforce learning. Encourage critical thinking and student engagement through challenges, fun facts, and practical experiment suggestions. 
                            If a student has doubts, be patient and rephrase explanations in different ways. When helpful, provide illustrations or bullet-point summaries. Always promote environmental awareness and scientific curiosity in a positive and inspiring way!."""
    
    # Faz a chamada para a API do Groq
    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "system",
                "content": prompt
            },
            {
                "role": "user",
                "content": message
            }
        ],
        model="mixtral-8x7b-32768",  # ou outro modelo disponível no Groq
        temperature=0.7,
        max_tokens=150
    )
    
    # Retorna a resposta gerada
    return chat_completion.choices[0].message.content

# Cria a interface Gradio

    
demo = gr.ChatInterface(
    generate_response,
    title="Ecowe",
    description="Educational Ecology Chatbot."
)

# Inicia a interface
demo.launch()