Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from groq import Groq
|
| 3 |
+
|
| 4 |
+
def generate_response(input_text):
|
| 5 |
+
client = Groq()
|
| 6 |
+
|
| 7 |
+
stream = client.chat.completions.create(
|
| 8 |
+
messages=[
|
| 9 |
+
{"role": "system", "content": "you are a helpful assistant."},
|
| 10 |
+
{"role": "user", "content": input_text}
|
| 11 |
+
],
|
| 12 |
+
model="mixtral-8x7b-32768",
|
| 13 |
+
temperature=0.5,
|
| 14 |
+
max_tokens=1024,
|
| 15 |
+
top_p=1,
|
| 16 |
+
stop=None,
|
| 17 |
+
stream=True,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
response = ""
|
| 21 |
+
for chunk in stream:
|
| 22 |
+
response += chunk.choices[0].delta.content
|
| 23 |
+
|
| 24 |
+
return response
|
| 25 |
+
|
| 26 |
+
# Define the Gradio UI
|
| 27 |
+
inputs = gr.inputs.Textbox(label="Enter your question")
|
| 28 |
+
outputs = gr.outputs.Textbox(label="Model Response")
|
| 29 |
+
|
| 30 |
+
gr.Interface(
|
| 31 |
+
fn=generate_response,
|
| 32 |
+
inputs=inputs,
|
| 33 |
+
outputs=outputs,
|
| 34 |
+
title="Language Model Assistant",
|
| 35 |
+
description="Ask questions and get responses from a language model.",
|
| 36 |
+
).launch(show_api=False, share=True)
|