admin08077 commited on
Commit
c06ff17
·
verified ·
1 Parent(s): 6dbd1ba

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client
3
+
4
+ # Connect to your existing Gradio apps
5
+ grounded_client = Client("admin08077/veo")
6
+ image_client = Client("admin08077/picgenai")
7
+ chat_client = Client("admin08077/genai")
8
+
9
+ def generate_book(topic):
10
+ # Step 1: Get grounded fact-based response
11
+ try:
12
+ grounded_response = grounded_client.predict(
13
+ prompt=topic,
14
+ api_name="/generate_grounded_response"
15
+ )
16
+ except Exception as e:
17
+ grounded_response = f"Error getting grounded response: {e}"
18
+
19
+ # Step 2: Generate image and caption
20
+ try:
21
+ image_caption = image_client.predict(
22
+ prompt=topic,
23
+ api_name="/generate_image_and_caption"
24
+ )
25
+ except Exception as e:
26
+ image_caption = f"Error generating image: {e}"
27
+
28
+ # Step 3: Generate narrative continuation
29
+ try:
30
+ gemini_narrative = chat_client.predict(
31
+ user_input=f"Write a short story based on: {topic}",
32
+ api_name="/chat_with_gemini"
33
+ )
34
+ except Exception as e:
35
+ gemini_narrative = f"Error with Gemini chat: {e}"
36
+
37
+ # Assemble the "book" content
38
+ book_text = f"""# Illustrated Book: "{topic.title()}"
39
+
40
+ ## Chapter 1: The Facts
41
+ {grounded_response}
42
+
43
+ ## Chapter 2: The Picture
44
+ 🖼️ {image_caption}
45
+
46
+ ## Chapter 3: The Story
47
+ {gemini_narrative}
48
+ """
49
+ return book_text
50
+
51
+ with gr.Blocks() as demo:
52
+ gr.Markdown("## 📖 AI-Generated Illustrated Book")
53
+ topic = gr.Textbox(label="Enter a topic for your book", placeholder="e.g. Who won the euro 2024?")
54
+ output = gr.Textbox(label="Generated Book", lines=20)
55
+ button = gr.Button("Generate Book")
56
+
57
+ button.click(fn=generate_book, inputs=topic, outputs=output)
58
+
59
+ demo.launch()