Spaces:
Running
Running
File size: 3,574 Bytes
26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c 26d467b 720745c |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# import gradio as gr
# from groq import Groq
# client = Groq(
# api_key=("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"),
# )
# def generate_response(input_text):
# chat_completion = client.chat.completions.create(
# messages=[
# {
# "role": "user",
# "content": input_text,
# }
# ],
# model="llama3-8b-8192",
# )
# return chat_completion.choices[0].message.content
# iface = gr.Interface(
# fn=generate_response,
# inputs=gr.Textbox(label="ورودی" , lines=2, placeholder="اینجا یه چی بپرس... "),
# outputs=gr.Textbox(label="جواب"),
# title="💬 Parviz GPT",
# description="زنده باد",
# theme="dark",
# allow_flagging="never"
# )
# iface.launch()
import gradio as gr
from groq import Groq
import time
client = Groq(api_key="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")
def generate_response(message, chat_history):
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": message}],
model="llama3-8b-8192",
)
bot_message = chat_completion.choices[0].message.content
for i in range(0, len(bot_message), 10):
yield chat_history + [(message, bot_message[:i + 10])]
time.sleep(0.1)
yield chat_history + [(message, bot_message)]
with gr.Blocks() as demo:
gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1><p style='text-align: center; color: #e0e0e0;'>زنده باد</p>")
chatbot = gr.Chatbot(label="جواب")
msg = gr.Textbox(label="ورودی", placeholder="اینجا یه چی بپرس... ", lines=1)
msg.submit(generate_response, [msg, chatbot], chatbot)
clear = gr.ClearButton([msg, chatbot])
demo.launch()
# import gradio as gr
# import torch
# from transformers import AutoTokenizer, AutoModelForCausalLM
# tokenizer = AutoTokenizer.from_pretrained("universitytehran/PersianMind-v1.0", use_fast=True)
# model = AutoModelForCausalLM.from_pretrained(
# "universitytehran/PersianMind-v1.0",
# torch_dtype=torch.bfloat16
# ).to("cpu")
# CONTEXT = (
# "This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
# "an NLP expert, to help you with various tasks such as answering questions, "
# "providing recommendations, and assisting with decision-making. Ask it anything!"
# )
# pretokenized_context = tokenizer(CONTEXT, return_tensors="pt").input_ids.to("cpu")
# def generate_response(message, chat_history):
# prompt = torch.cat(
# [pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")],
# dim=1
# )
# with torch.no_grad():
# outputs = model.generate(
# prompt,
# max_new_tokens=32,
# temperature=0.6,
# top_k=20,
# top_p=0.8,
# do_sample=True
# )
# result = tokenizer.decode(outputs[0], skip_special_tokens=True)
# response = result.split("ParvizGPT:")[-1].strip()
# return chat_history + [(message, response)]
# with gr.Blocks() as demo:
# gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1>")
# chatbot = gr.Chatbot(label="Response")
# msg = gr.Textbox(label="Input", placeholder="Ask your question...", lines=1)
# msg.submit(generate_response, [msg, chatbot], chatbot)
# gr.ClearButton([msg, chatbot])
# demo.launch() |