Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -343,6 +343,54 @@
|
|
343 |
# if __name__ == "__main__":
|
344 |
# demo.launch()
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
import os
|
347 |
import subprocess
|
348 |
import gradio as gr
|
@@ -382,11 +430,16 @@ def get_text_response(user_message, history=None):
|
|
382 |
chat_history = history + [f"User: {user_message}"]
|
383 |
llm = ChatOpenAI(temperature=0.5, model="gpt-3.5-turbo")
|
384 |
response = llm({"chat_history": "\n".join(chat_history), "user_message": user_message})
|
385 |
-
|
386 |
-
|
|
|
387 |
|
388 |
# Create a Gradio chat interface
|
389 |
-
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
390 |
|
391 |
if __name__ == "__main__":
|
392 |
demo.launch()
|
@@ -397,3 +450,4 @@ if __name__ == "__main__":
|
|
397 |
|
398 |
|
399 |
|
|
|
|
343 |
# if __name__ == "__main__":
|
344 |
# demo.launch()
|
345 |
|
346 |
+
# import os
|
347 |
+
# import subprocess
|
348 |
+
# import gradio as gr
|
349 |
+
|
350 |
+
# # Install necessary packages
|
351 |
+
# subprocess.check_call(["pip", "install", "-U", "langchain-openai", "gradio", "langchain-community"])
|
352 |
+
|
353 |
+
# from langchain_openai import ChatOpenAI
|
354 |
+
# from langchain.prompts import PromptTemplate
|
355 |
+
# from langchain.memory import ConversationBufferMemory
|
356 |
+
|
357 |
+
# # Set OpenAI API Key
|
358 |
+
# OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
|
359 |
+
|
360 |
+
# # Define the template for the chatbot's response
|
361 |
+
# template = """You are a helpful assistant to answer all user queries.
|
362 |
+
# {chat_history}
|
363 |
+
# User: {user_message}
|
364 |
+
# Chatbot:"""
|
365 |
+
|
366 |
+
# # Define the prompt template
|
367 |
+
# prompt = PromptTemplate(
|
368 |
+
# input_variables=["chat_history", "user_message"],
|
369 |
+
# template=template
|
370 |
+
# )
|
371 |
+
|
372 |
+
# # Initialize conversation memory
|
373 |
+
# memory = ConversationBufferMemory(memory_key="chat_history")
|
374 |
+
|
375 |
+
# # Function to get chatbot response
|
376 |
+
# def get_text_response(user_message, history=None):
|
377 |
+
# # Ensure history is a list
|
378 |
+
# if history is None:
|
379 |
+
# history = []
|
380 |
+
|
381 |
+
# # Prepare the conversation history
|
382 |
+
# chat_history = history + [f"User: {user_message}"]
|
383 |
+
# llm = ChatOpenAI(temperature=0.5, model="gpt-3.5-turbo")
|
384 |
+
# response = llm({"chat_history": "\n".join(chat_history), "user_message": user_message})
|
385 |
+
|
386 |
+
# return response['choices'][0]['message']['content']
|
387 |
+
|
388 |
+
# # Create a Gradio chat interface
|
389 |
+
# demo = gr.Interface(fn=get_text_response, inputs=["text", "state"], outputs="text")
|
390 |
+
|
391 |
+
# if __name__ == "__main__":
|
392 |
+
# demo.launch()
|
393 |
+
|
394 |
import os
|
395 |
import subprocess
|
396 |
import gradio as gr
|
|
|
430 |
chat_history = history + [f"User: {user_message}"]
|
431 |
llm = ChatOpenAI(temperature=0.5, model="gpt-3.5-turbo")
|
432 |
response = llm({"chat_history": "\n".join(chat_history), "user_message": user_message})
|
433 |
+
|
434 |
+
# Return the response and updated history
|
435 |
+
return response['choices'][0]['message']['content'], chat_history
|
436 |
|
437 |
# Create a Gradio chat interface
|
438 |
+
demo = gr.Interface(
|
439 |
+
fn=get_text_response,
|
440 |
+
inputs=["text", "state"],
|
441 |
+
outputs=["text", "state"],
|
442 |
+
)
|
443 |
|
444 |
if __name__ == "__main__":
|
445 |
demo.launch()
|
|
|
450 |
|
451 |
|
452 |
|
453 |
+
|