ProPerNounpYK commited on
Commit
0348566
·
verified ·
1 Parent(s): 0ef23a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+ from PIL import Image
4
+ import gradio as gr
5
+
6
+ # Load text-to-image model
7
+ text_to_image_model = torch.hub.load("ProPerNounpYK/texttoimage", map_location=torch.device("cuda" if torch.cuda.is_available() else "cpu"))
8
+
9
+ # Load chat model
10
+ chat_model = AutoModelForSeq2SeqLM.from_pretrained("ProPerNounpYK/chat")
11
+ chat_tokenizer = AutoTokenizer.from_pretrained("ProPerNounpYK/chat")
12
+
13
+ # Create multimodal interface
14
+ interface = gr.Interface(
15
+ fn=lambda input_text, input_image: generate_response(input_text, input_image),
16
+ inputs=["text", "image"],
17
+ outputs=["text", "image"],
18
+ title="Multimodal Conversational AI",
19
+ description="Talk to me, and I'll respond with images!"
20
+ )
21
+
22
+ def generate_response(input_text, input_image):
23
+ # Process input text using chat model
24
+ chat_output = chat_model(input_text)
25
+ chat_response = chat_tokenizer.decode(chat_output, skip_special_tokens=True)
26
+
27
+ # Process input image using text-to-image model
28
+ generated_image = text_to_image_model(input_text, input_image)
29
+
30
+ # Return response as a tuple of text and image
31
+ return chat_response, generated_image
32
+
33
+ # Launch the interface
34
+ interface.launch()