Spaces:
Sleeping
Sleeping
yazanateer
commited on
Commit
•
2f286b3
1
Parent(s):
fc70fc7
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain_groq import ChatGroq
|
3 |
+
from langchain_core.messages import HumanMessage
|
4 |
+
|
5 |
+
|
6 |
+
GROQ_API_KEY = "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"
|
7 |
+
|
8 |
+
# Initialize Groq
|
9 |
+
chat_model = ChatGroq(model_name="mixtral-8x7b-32768", api_key=GROQ_API_KEY)
|
10 |
+
|
11 |
+
def generate_response(question):
|
12 |
+
"""Generate a response using Groq."""
|
13 |
+
try:
|
14 |
+
input_text = f"Tell me about {question} in the context of AI-assisted language learning."
|
15 |
+
messages = [HumanMessage(content=input_text)]
|
16 |
+
response = chat_model.invoke(messages)
|
17 |
+
return response.content
|
18 |
+
except Exception as e:
|
19 |
+
return f"An error occurred: {str(e)}"
|
20 |
+
|
21 |
+
# Create Gradio interface
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=generate_response,
|
24 |
+
inputs=gr.Textbox(lines=2, label="Enter a topic related to AI and language learning"),
|
25 |
+
outputs=gr.Textbox(label="Response", lines=10),
|
26 |
+
title="AI-Assisted Language Learning Platform",
|
27 |
+
description="Ask about topics in AI-assisted language learning.",
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the Gradio app
|
31 |
+
iface.launch()
|