BruceLee1234 commited on
Commit
6208bbe
·
verified ·
1 Parent(s): 6e6fe92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -1,17 +1,32 @@
1
- from gradio_client import Client
 
2
 
3
- # Use the space URL where your Gradio app is hosted
4
- client = Client("BruceLee1234/HelpingAIMentalAssistance")
 
 
5
 
6
- result = client.predict(
7
- message="Hello, Hope you are having a great day!!",
8
- system_message="You are HelpingAI mental assistance. You identify the flow of dialogue the user chats and respond in the same emotional state. Make it realistic in HelpfulAI style",
9
- max_tokens=2048,
10
- temperature=0.7,
11
- top_p=0.95,
12
- top_k=40,
13
- repeat_penalty=1.1,
14
- api_name="/chat" # This is the endpoint exposed by Hugging Face
 
 
 
 
 
 
 
 
 
 
 
15
  )
16
 
17
- print(result)
 
 
1
+ import gradio as gr
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
 
4
+ # Load the GPT-2 model and tokenizer
5
+ model_name = "gpt2" # You can also try "gpt2-medium" or "gpt2-large" for more powerful models
6
+ model = GPT2LMHeadModel.from_pretrained(model_name)
7
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
8
 
9
+ # Define the chat function
10
+ def chat_function(user_input):
11
+ # Encode the input
12
+ inputs = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors="pt")
13
+
14
+ # Generate a response from the model
15
+ outputs = model.generate(inputs, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7)
16
+
17
+ # Decode the generated response
18
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
19
+
20
+ return response
21
+
22
+ # Create the Gradio interface
23
+ iface = gr.Interface(
24
+ fn=chat_function, # Function to call
25
+ inputs=gr.Textbox(label="You"), # Textbox for user input
26
+ outputs=gr.Textbox(label="Chatbot Response"), # Textbox for model output
27
+ title="GPT-2 Chatbot", # Title of the app
28
+ description="A simple chatbot powered by GPT-2. Enter a message to chat with the bot." # Description
29
  )
30
 
31
+ # Launch the app
32
+ iface.launch()