Abhisesh7 commited on
Commit
6e108be
·
verified ·
1 Parent(s): 1e5986b

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -55
app.py DELETED
@@ -1,55 +0,0 @@
1
- import gradio as gr
2
- import requests
3
- from PIL import Image
4
- from io import BytesIO
5
-
6
- # Hugging Face API URL and Token
7
- API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
8
- headers = {"Authorization": f"Bearer YOUR_HF_API_KEY"} # Replace with your Hugging Face API key
9
-
10
- # Function to query the Hugging Face API for image generation
11
- def query_hf_api(prompt):
12
- response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
13
- if response.status_code != 200:
14
- return None # Return None if there's an error in the API call
15
- return response.content
16
-
17
- # Function to generate comic panels based on story description
18
- def generate_comic_panels(story_description):
19
- # Creating prompts for three key scenes from the story
20
- scenes = [f"{story_description} - Scene {i+1}" for i in range(3)]
21
-
22
- images = []
23
- for scene in scenes:
24
- # Querying the API for each scene
25
- image_bytes = query_hf_api(scene)
26
- if image_bytes is None:
27
- return ["Error: Could not generate images, check the API or story."]
28
- image = Image.open(BytesIO(image_bytes)) # Convert bytes to image
29
- images.append(image)
30
-
31
- return images
32
-
33
- # Function to set up the Gradio interface
34
- def create_interface():
35
- description = """
36
- Welcome to GenArt Narrative! Enter a brief story description and watch it transform into a comic-strip format,
37
- with images generated for key scenes of your story.
38
- """
39
-
40
- # Textbox for input and gallery for output
41
- inputs = gr.Textbox(lines=5, placeholder="Enter a short story description here...", label="Story Description")
42
- outputs = gr.Gallery(label="Generated Comic Panels", columns=3) # Remove the .style()
43
-
44
- # Launch the interface
45
- gr.Interface(
46
- fn=generate_comic_panels,
47
- inputs=inputs,
48
- outputs=outputs,
49
- title="GenArt Narrative",
50
- description=description,
51
- ).launch()
52
-
53
- # Run the app
54
- if __name__ == "__main__":
55
- create_interface()