Update app.py
Browse files
app.py
CHANGED
|
@@ -20,35 +20,57 @@
|
|
| 20 |
|
| 21 |
|
| 22 |
# Sample code for AI language model interaction
|
| 23 |
-
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
| 24 |
-
import gradio
|
| 25 |
|
| 26 |
|
| 27 |
-
def simptok(data):
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
inputs = "text",
|
| 52 |
outputs = "text"
|
| 53 |
)
|
| 54 |
gradio_interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
# Sample code for AI language model interaction
|
| 23 |
+
# from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
| 24 |
+
# import gradio
|
| 25 |
|
| 26 |
|
| 27 |
+
# def simptok(data):
|
| 28 |
+
# # Load pre-trained model and tokenizer (using the transformers library)
|
| 29 |
+
# model_name = "gpt2"
|
| 30 |
+
# tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 31 |
+
# model = GPT2LMHeadModel.from_pretrained(model_name)
|
| 32 |
|
| 33 |
+
# # User input
|
| 34 |
+
# user_input = data
|
| 35 |
|
| 36 |
+
# # Tokenize input
|
| 37 |
+
# input_ids = tokenizer.encode(user_input, return_tensors="pt")
|
| 38 |
|
| 39 |
+
# # Generate response
|
| 40 |
+
# output = model.generate(input_ids, max_length=50, num_return_sequences=1)
|
| 41 |
+
# response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 42 |
+
# return response
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# def responsenew(data):
|
| 46 |
+
# return simptok(data)
|
| 47 |
+
|
| 48 |
|
| 49 |
+
from hugchat import hugchat
|
| 50 |
+
import gradio as gr
|
| 51 |
+
import time
|
| 52 |
|
| 53 |
+
# Create a chatbot connection
|
| 54 |
+
chatbot = hugchat.ChatBot(cookie_path="cookies.json")
|
| 55 |
|
| 56 |
+
# New a conversation (ignore error)
|
| 57 |
+
id = chatbot.new_conversation()
|
| 58 |
+
chatbot.change_conversation(id)
|
| 59 |
|
| 60 |
+
|
| 61 |
+
def get_answer(data):
|
| 62 |
+
return chatbot.chat(data)
|
| 63 |
+
|
| 64 |
+
gradio_interface = gr.Interface(
|
| 65 |
+
fn = get_answer,
|
| 66 |
inputs = "text",
|
| 67 |
outputs = "text"
|
| 68 |
)
|
| 69 |
gradio_interface.launch()
|
| 70 |
+
|
| 71 |
+
# gradio_interface = gradio.Interface(
|
| 72 |
+
# fn = responsenew,
|
| 73 |
+
# inputs = "text",
|
| 74 |
+
# outputs = "text"
|
| 75 |
+
# )
|
| 76 |
+
# gradio_interface.launch()
|