measmonysuon commited on
Commit
2abb7ab
·
verified ·
1 Parent(s): 315eb1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -47
app.py CHANGED
@@ -3,13 +3,9 @@ import google.generativeai as genai
3
  import logging
4
  import gradio as gr
5
  from dotenv import load_dotenv
6
- from flask import Flask, send_from_directory
7
  import os
8
  import threading
9
 
10
- # Initialize Flask app
11
- app = Flask(__name__)
12
-
13
 
14
  # Load environment variables from .env file
15
  load_dotenv()
@@ -75,56 +71,39 @@ def generate_response(user_input):
75
  logger.error(f"Error during GenAI processing: {e}")
76
  return "Sorry, I can't answer this query right now but I will improve from time to time."
77
 
78
- # Define Gradio interface
79
  def gradio_handle_update(user_input):
80
  return generate_response(user_input)
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  iface = gr.Interface(
 
83
  fn=gradio_handle_update,
84
  inputs=gr.Textbox(label="User Input"),
85
  outputs=gr.Textbox(label="Bot Response"),
86
- live=True
 
 
87
  )
88
 
89
- @app.route('/')
90
- @app.route('/')
91
- def index():
92
- html_content = """
93
- <!DOCTYPE html>
94
- <html lang="en">
95
- <head>
96
- <meta charset="UTF-8">
97
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
98
- <title>AforativeBot</title>
99
- </head>
100
- <body>
101
- <h1>AforativeBot</h1>
102
- <p><strong>AforativeBot</strong> is designed for private companies to maximize client satisfaction and improve communication in the AI era for Aforative Media Company.</p>
103
-
104
- <h2>About Us</h2>
105
- <p>Founded in 2016, <strong>Aforative Media (AF)</strong> has been dedicated to providing a wide range of services for nearly five years. We specialize in photography, videography, video hybrid meetings, and conference live-streaming for both local and international clients. Throughout our journey, we have continually learned and improved, striving to enhance our services every day.</p>
106
-
107
- <p>We are proud to be a partner in digital marketing content for the hotel and tourism industry. In a digital world that demands engaging and creative content, we are committed to delivering just that. Additionally, we cherish the role of preserving precious memories for couples, families, and corporate entities.</p>
108
-
109
- <p>Our goal is to be a reliable partner for your business, helping you grow with impactful digital content. With <strong>Aforative Media</strong>, you and your business will stay updated and keep pace with regional and global trends.</p>
110
-
111
- <p>Connect with us via our <a href="https://t.me/aforativemedia">Telegram Chatbot</a>.</p>
112
- </body>
113
- </html>
114
- """
115
- return html_content
116
-
117
-
118
- def run_gradio():
119
- try:
120
- iface.launch(server_port=7860) # No share=True, specify a port if needed
121
- except Exception as e:
122
- logger.error(f"Error launching Gradio: {e}")
123
-
124
  if __name__ == "__main__":
125
- # Run Gradio in a separate thread
126
- gradio_thread = threading.Thread(target=run_gradio)
127
- gradio_thread.start()
128
-
129
- # Run Flask app
130
- app.run(port=5000, debug=True)
 
3
  import logging
4
  import gradio as gr
5
  from dotenv import load_dotenv
 
6
  import os
7
  import threading
8
 
 
 
 
9
 
10
  # Load environment variables from .env file
11
  load_dotenv()
 
71
  logger.error(f"Error during GenAI processing: {e}")
72
  return "Sorry, I can't answer this query right now but I will improve from time to time."
73
 
 
74
  def gradio_handle_update(user_input):
75
  return generate_response(user_input)
76
 
77
+ # Static text as HTML
78
+ static_html = """
79
+ <!DOCTYPE html>
80
+ <html lang="en">
81
+ <head>
82
+ <meta charset="UTF-8">
83
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
84
+ <title>AforativeBot</title>
85
+ </head>
86
+ <body>
87
+ <h1>AforativeBot</h1>
88
+ <p><strong>AforativeBot</strong> is designed for private companies to maximize client satisfaction and improve communication in the AI era for Aforative Media Company.</p>
89
+ <h2>About Us</h2>
90
+ <p>Founded in 2016, <strong>Aforative Media (AF)</strong> has been dedicated to providing a wide range of services for nearly five years. We specialize in photography, videography, video hybrid meetings, and conference live-streaming for both local and international clients. Throughout our journey, we have continually learned and improved, striving to enhance our services every day.</p>
91
+ <p>We are proud to be a partner in digital marketing content for the hotel and tourism industry. In a digital world that demands engaging and creative content, we are committed to delivering just that. Additionally, we cherish the role of preserving precious memories for couples, families, and corporate entities.</p>
92
+ <p>Our goal is to be a reliable partner for your business, helping you grow with impactful digital content. With <strong>Aforative Media</strong>, you and your business will stay updated and keep pace with regional and global trends.</p>
93
+ <p>Connect with us via our <a href="https://t.me/aforativemedia">Telegram Chatbot</a>.</p>
94
+ </body>
95
+ </html>
96
+ """
97
+
98
  iface = gr.Interface(
99
+ description=static_html
100
  fn=gradio_handle_update,
101
  inputs=gr.Textbox(label="User Input"),
102
  outputs=gr.Textbox(label="Bot Response"),
103
+ live=True,
104
+ title="AforativeBot",
105
+
106
  )
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  if __name__ == "__main__":
109
+ iface.launch()