Spaces:
Sleeping
Sleeping
import gradio as gr | |
from langchain_groq import ChatGroq | |
from langchain_core.messages import HumanMessage | |
GROQ_API_KEY = "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" | |
# Initialize Groq | |
chat_model = ChatGroq(model_name="mixtral-8x7b-32768", api_key=GROQ_API_KEY) | |
def generate_response(question): | |
"""Generate a response using Groq.""" | |
try: | |
input_text = f"Tell me about {question} in the context of AI-assisted language learning." | |
messages = [HumanMessage(content=input_text)] | |
response = chat_model.invoke(messages) | |
return response.content | |
except Exception as e: | |
return f"An error occurred: {str(e)}" | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=generate_response, | |
inputs=gr.Textbox(lines=2, label="Enter a topic related to AI and language learning"), | |
outputs=gr.Textbox(label="Response", lines=10), | |
title="AI-Assisted Language Learning Platform", | |
description="Ask about topics in AI-assisted language learning.", | |
) | |
# Launch the Gradio app | |
iface.launch() | |