Nepjune commited on
Commit
a761387
·
verified ·
1 Parent(s): e5af486

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -32
app.py CHANGED
@@ -1,9 +1,12 @@
 
 
1
  from transformers import pipeline, BlipForConditionalGeneration, BlipProcessor
2
  import torchaudio
3
  from torchaudio.transforms import Resample
4
  import torch
5
  import gradio as gr
6
- from flask import Flask, jsonify, render_template_string
 
7
 
8
  # Initialize TTS model from Hugging Face
9
  tts_model_name = "Kamonwan/blip-image-captioning-new"
@@ -14,8 +17,6 @@ model_id = "Kamonwan/blip-image-captioning-new"
14
  blip_model = BlipForConditionalGeneration.from_pretrained(model_id)
15
  blip_processor = BlipProcessor.from_pretrained(model_id)
16
 
17
- app = Flask(__name__)
18
-
19
  def generate_caption(image):
20
  # Generate caption from image using Blip model
21
  inputs = blip_processor(images=image, return_tensors="pt")
@@ -38,35 +39,7 @@ def generate_caption_api():
38
 
39
  @app.route('/')
40
  def index():
41
- return render_template_string("""
42
- <!DOCTYPE html>
43
- <html lang="en">
44
- <head>
45
- <meta charset="UTF-8">
46
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
47
- <title>Gradio Interface</title>
48
- </head>
49
- <body>
50
- <h1>Gradio Interface</h1>
51
- {{ gr_interface|safe }}
52
- </body>
53
- </html>
54
- """, gr_interface=demo.get_interface())
55
 
56
  if __name__ == '__main__':
57
- demo = gr.Interface(
58
- fn=generate_caption,
59
- inputs=gr.Image(),
60
- outputs=[
61
- gr.Textbox(label="Generated caption"),
62
- gr.Button("Convert to Audio"),
63
- gr.Audio(type="filepath", label="Generated Audio")
64
- ],
65
- live=True
66
- )
67
-
68
- # Start Gradio interface
69
- demo.launch(share=True)
70
-
71
- # Start Flask app
72
  app.run(host='0.0.0.0', port=5000)
 
1
+ # app.py
2
+ from flask import Flask, render_template, request, jsonify
3
  from transformers import pipeline, BlipForConditionalGeneration, BlipProcessor
4
  import torchaudio
5
  from torchaudio.transforms import Resample
6
  import torch
7
  import gradio as gr
8
+
9
+ app = Flask(__name__)
10
 
11
  # Initialize TTS model from Hugging Face
12
  tts_model_name = "Kamonwan/blip-image-captioning-new"
 
17
  blip_model = BlipForConditionalGeneration.from_pretrained(model_id)
18
  blip_processor = BlipProcessor.from_pretrained(model_id)
19
 
 
 
20
  def generate_caption(image):
21
  # Generate caption from image using Blip model
22
  inputs = blip_processor(images=image, return_tensors="pt")
 
39
 
40
  @app.route('/')
41
  def index():
42
+ return render_template("index.html")
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  if __name__ == '__main__':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  app.run(host='0.0.0.0', port=5000)