File size: 1,518 Bytes
1c11ab9
d5926cb
 
2a6f9d8
d44d00e
d5926cb
2a6f9d8
1c11ab9
2a6f9d8
 
 
 
 
 
 
 
 
 
 
d5926cb
 
2a6f9d8
1c11ab9
 
2a6f9d8
1c11ab9
2a6f9d8
1c11ab9
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from transformers import pipeline
import gradio as gr

# Load the DialoGPT-medium model
chatbot = pipeline("text-generation", model="codealtgeek/DiabloGPT-medium-rickmorty")

# Detailed context about your watch company
context = """
You are a helpful assistant for WatchCo, a company that sells high-quality watches. Here is some information about our policies:

- Our return policy allows customers to return watches within 30 days for a full refund, as long as the watch is in its original condition.
- We offer a standard 1-year warranty on all watches, covering manufacturing defects.
- Extended warranties are available for purchase, extending coverage to 2 or 3 years.
- We sell three types of watches that are diver watches, dress watches and field watches.
- Prices of our watches start as low as 50 dollars.
- Our average shipping time is 2-weeks.
- There is also an option to get faster delhivery if needed, that is within 1-week. 

Please answer the user's question based on this information.
"""

# Function to generate a response
def generate_response(user_input):
    prompt = f"{context}\nUser: {user_input}\nAssistant:"
    response = chatbot(prompt, max_length=150, num_return_sequences=1)
    generated_text = response[0]["generated_text"]
    # Extract just the assistant's answer
    assistant_response = generated_text.split("Assistant:")[1].strip()
    return assistant_response

# Create the chat interface
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
iface.launch()