pratikshahp commited on
Commit
54cd41c
·
verified ·
1 Parent(s): 8663127

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ import gradio as gr
4
+ from langchain_huggingface import HuggingFaceEndpoint
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+ HF_TOKEN = os.getenv("HF_TOKEN")
9
+
10
+ # Initialize the Hugging Face endpoint for inference
11
+ llm = HuggingFaceEndpoint(
12
+ repo_id="meta-llama/Meta-Llama-3-8B", # Replace with your model repo
13
+ huggingfacehub_api_token=HF_TOKEN.strip(),
14
+ temperature=0.7,
15
+ max_new_tokens=200
16
+ )
17
+
18
+ # Function to handle chatbot response
19
+ def chatbot_response(message):
20
+ try:
21
+ response = llm(message)
22
+ return response
23
+ except Exception as e:
24
+ return f"Error: {e}"
25
+
26
+
27
+ # Gradio Interface for Chatbot without Guardrails
28
+ with gr.Blocks() as app_without_guardrails:
29
+ gr.Markdown("## Chatbot Without Guardrails")
30
+ gr.Markdown("This chatbot uses the model directly without applying any content filtering.")
31
+
32
+ # Input and output
33
+ with gr.Row():
34
+ user_input = gr.Textbox(label="Your Message", placeholder="Type here...")
35
+ response_output = gr.Textbox(label="Response", placeholder="Bot will respond here...")
36
+ submit_button = gr.Button("Send")
37
+
38
+ # Button click event
39
+ submit_button.click(
40
+ chatbot_response,
41
+ inputs=[user_input],
42
+ outputs=[response_output]
43
+ )
44
+
45
+ # Launch the app
46
+ if __name__ == "__main__":
47
+ app_without_guardrails.launch()