Spaces:
Runtime error
Runtime error
Update app.py
#1
by
Rishavjain01
- opened
app.py
CHANGED
|
@@ -1,29 +1,34 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from diffusers import DiffusionPipeline
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# Input prompt
|
| 17 |
-
prompt_input = gr.Textbox(label="Prompt", value="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
|
| 18 |
-
|
| 19 |
-
# Output image
|
| 20 |
-
output_image = gr.Image(label="Generated Image")
|
| 21 |
-
|
| 22 |
-
# Button to trigger image generation
|
| 23 |
-
generate_button = gr.Button("Generate Image")
|
| 24 |
-
|
| 25 |
-
# Bind button to function
|
| 26 |
-
generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
openai.api_key = os.getenv("GROQ_API_KEY")
|
| 6 |
+
openai.api_base = "https://api.groq.com/openai/v1"
|
| 7 |
|
| 8 |
+
def get_groq_response(message):
|
| 9 |
+
try:
|
| 10 |
+
response = openai.ChatCompletion.create(
|
| 11 |
+
model="llama-3.1-70b-versatile",
|
| 12 |
+
messages=[
|
| 13 |
+
|
| 14 |
+
{"role": "user","content":message},
|
| 15 |
+
]
|
| 16 |
+
)
|
| 17 |
+
return response.choices[0].message['content']
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {str(e)}"
|
| 20 |
|
| 21 |
+
def chatbot(user_input , history =[]):
|
| 22 |
+
bot_response = get_groq_response(user_input)
|
| 23 |
+
history.append((user_input, bot_response))
|
| 24 |
+
return history, history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
chat_interface = gr.Interface(
|
| 27 |
+
fn=chatbot,
|
| 28 |
+
inputs=["text","state"],
|
| 29 |
+
outputs=["chatbot","state"],
|
| 30 |
+
live=False,
|
| 31 |
+
title="My Chatbot",
|
| 32 |
+
description = "Mom: We have ChatGPT at home,\n ChatGPT at Home:"
|
| 33 |
+
)
|
| 34 |
+
chat_interface.launch()
|