Spaces:
Running
Running
| from gradio_client import Client | |
| import json | |
| import gradio as gr | |
| import os | |
| custom_css = """ | |
| #component-11{ | |
| border: 2px solid #0074d9; | |
| background: #0074d9; | |
| } | |
| footer {visibility: hidden} | |
| """ | |
| def generate_answer(Question=""): | |
| try: | |
| client = Client(os.getenv("host"), hf_token=os.getenv("nekot")) | |
| json_path = client.predict(fn_index=1) # Auto-detect the path | |
| response = client.predict(Question, json_path, fn_index=0) | |
| with open(response[1], 'r') as json_file: | |
| data = json.load(json_file)[0] | |
| prompt = data[0] | |
| answer = data[1] | |
| return answer | |
| except Exception as e: | |
| print("An error has occurred: ", e) | |
| return "Sorry, we are not available right now." | |
| examples = ["Is Nigerian Senator, Enyinnaya Abaribe, shot dead?", "Liberia has the world's highest rainfall rate: true or false"] | |
| description = "Ask your question" | |
| article = "<p><strong>Disclaimer:</strong> Dubawa Chatbot is designed to assist users with fact-checked information and answer questions related to Dubawa and fact-checked articles. While we strive to provide accurate and reliable information, please be aware that the chatbot's responses are generated based on available data and may not always reflect the most up-to-date information. Users are encouraged to cross-verify information for critical decisions and consult trusted sources for any specific or sensitive inquiries.</p>" | |
| title = "Dubawa Chatbot" | |
| thumbnail = 'Dubawa' | |
| demo = gr.Interface(fn=generate_answer, inputs="text", outputs="text", title=title, description=description,cache_examples=True, examples=examples, article=article, thumbnail=thumbnail,allow_flagging=True, css=custom_css ) | |
| demo.launch(show_api=False, show_tips=True) |