Files changed (1) hide show
  1. app.py +29 -24
app.py CHANGED
@@ -1,29 +1,34 @@
1
- import torch
2
- from diffusers import DiffusionPipeline
3
  import gradio as gr
 
 
4
 
5
- # Load the diffusion pipeline for CogVideoX model
6
- pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-5b-I2V", torch_dtype=torch.float16)
7
 
8
- def generate_image(prompt):
9
- image = pipe(prompt).images[0]
10
- return image
 
 
 
 
 
 
 
 
 
11
 
12
- # Set up Gradio interface
13
- with gr.Blocks() as demo:
14
- gr.Markdown("# Image Generation using CogVideoX Diffusers")
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
- # Launch Gradio app
29
- demo.launch()
 
 
 
 
 
 
 
 
 
 
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()