SarowarSaurav commited on
Commit
53edc6a
1 Parent(s): f0ffbd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
  # Define the knowledge base as a dictionary
4
  knowledge_base = {
@@ -691,24 +692,33 @@ knowledge_base = {
691
 
692
  }
693
 
694
- # Define the Gradio interface function
695
- def chatbot_interface(acronym):
696
- acronym = acronym.strip().upper() # Remove leading/trailing whitespace and convert to uppercase
697
- if acronym in knowledge_base:
698
- response = f"Answer: {knowledge_base[acronym]}"
699
- else:
700
- response = "Not found in the BATCCAPEDIA"
 
 
 
 
 
 
 
 
 
 
701
  return response
702
 
703
- # Create the Gradio interface
704
  iface = gr.Interface(
705
- fn=chatbot_interface,
706
  inputs="text",
707
  outputs="text",
708
  title="BATB Acronym Finder",
709
  description="Dictionary of Abbreviations & Acronyms",
710
- theme='default'
 
711
  )
712
 
713
- # Launch the interface
714
- iface.launch()
 
1
  import gradio as gr
2
+ from flask import Flask, render_template_string, request, jsonify
3
 
4
  # Define the knowledge base as a dictionary
5
  knowledge_base = {
 
692
 
693
  }
694
 
695
+ app = Flask(__name__)
696
+
697
+ @app.route('/')
698
+ def index():
699
+ return render_template_string(open('index.html').read())
700
+
701
+ @app.route('/get_abbreviation', methods=['POST'])
702
+ def get_abbreviation():
703
+ acronym = request.form['acronym'].strip().upper()
704
+ response = knowledge_base.get(acronym, "Not found in the BATCCAPEDIA")
705
+ return jsonify({"response": response})
706
+
707
+ if __name__ == '__main__':
708
+ app.run()
709
+
710
+ def gradio_ui(acronym):
711
+ response = knowledge_base.get(acronym.strip().upper(), "Not found in the BATCCAPEDIA")
712
  return response
713
 
 
714
  iface = gr.Interface(
715
+ fn=gradio_ui,
716
  inputs="text",
717
  outputs="text",
718
  title="BATB Acronym Finder",
719
  description="Dictionary of Abbreviations & Acronyms",
720
+ theme='default',
721
+ live=True
722
  )
723
 
724
+ iface.launch(app=app, inline=True)