File size: 1,707 Bytes
148ef88
 
d38ee29
723b915
148ef88
 
 
 
617870c
148ef88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f23aba5
148ef88
 
 
 
 
 
 
 
 
 
 
 
 
 
108a4bc
40ceffb
148ef88
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
import openai
import os
openai.api_key = os.getenv("OPENAI_API_KEY")
import csv
import json

# Define the CSV file input path
csv_file_path = "modak_qa.csv"

# Initialize an empty list to store the data
data = []

# Open the CSV file for reading
with open(csv_file_path, mode='r', newline='') as csv_file:
    # Create a CSV reader object
    csv_reader = csv.DictReader(csv_file)

    # Iterate through the CSV data and append it to the list
    for row in csv_reader:
        data.append(row)

# Convert the list of dictionaries to a JSON string
json_file = json.dumps(data, indent=4)

def respond(message, chat_history):
    global json_file
    prompt = f"You are a conversational chatbot.Answer all questions ***{message}*** smoothly. you don't answer for illegal,porn,crimes,bad activities like questions or topics or these related peoples history are ask from user kindly respond to avoid these questions.you don't answer about porn peoples.You can answer only related to this json file ***{json_file}*** questions."
    response = openai.Completion.create(
    engine="text-davinci-003",  # You can choose a different engine if needed
    prompt=prompt,
    max_tokens=500,  # Adjust max_tokens as needed
    temperature=0,  # Adjust temperature as needed
    )

    # Extract and print the generated text
    translated_text = response.choices[0].text.strip()
    chat_history.append((message, translated_text))
    return "", chat_history


with gr.Blocks() as demo:
    chatbot = gr.Chatbot()
    #chatbot = gr.Chatbot().style(height=350)
    msg = gr.Textbox()
    clear = gr.ClearButton([msg, chatbot])
    msg.submit(respond, [msg, chatbot], [msg, chatbot])

demo.launch()