Spaces:
Sleeping
Sleeping
prabinpanta0
commited on
Commit
•
5f154d9
1
Parent(s):
71cb103
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
# from transformers import pipeline
|
4 |
+
# from huggingface_hub import login
|
5 |
+
|
6 |
+
# # Get the Hugging Face token from environment variables
|
7 |
+
# HF_TOKEN = os.getenv('HF')
|
8 |
+
|
9 |
+
# if not HF_TOKEN:
|
10 |
+
# raise ValueError("The HF environment variable is not set. Please set it to your Hugging Face token.")
|
11 |
+
|
12 |
+
# # Authenticate with Hugging Face and save the token to the Git credentials helper
|
13 |
+
# login(HF_TOKEN, add_to_git_credential=True)
|
14 |
+
|
15 |
+
# Create the pipeline for text generation using the specified model
|
16 |
+
# pipe = pipeline("text-generation", model="distilbert/distilgpt2", token=HF_TOKEN)
|
17 |
+
pipe = pipeline("text-generation", model="openai-community/gpt2-medium")
|
18 |
+
|
19 |
+
# Define the initial prompt for the system
|
20 |
+
system_prompt = """
|
21 |
+
You are an AI model designed to provide concise information about big data analytics across various fields without mentioning the question. Respond with a focused, one-line answer that captures the essence of the key risk, benefit, or trend associated with the topic.
|
22 |
+
|
23 |
+
input: What do you consider the most significant risk of over-reliance on big data analytics in stock market risk management?
|
24 |
+
output: Increased market volatility.
|
25 |
+
|
26 |
+
input: What is a major benefit of big data analytics in healthcare?
|
27 |
+
output: Enhanced patient care through personalized treatment.
|
28 |
+
|
29 |
+
input: What is a key challenge of big data analytics in retail?
|
30 |
+
output: Maintaining data privacy and security.
|
31 |
+
|
32 |
+
input: What is a primary advantage of big data analytics in manufacturing?
|
33 |
+
output: Improved production efficiency and predictive maintenance.
|
34 |
+
|
35 |
+
input: What is a significant risk associated with big data analytics in education?
|
36 |
+
output: Potential widening of the achievement gap if data is not used equitably.
|
37 |
+
"""
|
38 |
+
|
39 |
+
def generate(text):
|
40 |
+
try:
|
41 |
+
# Combine the system prompt with the user's input
|
42 |
+
prompt = system_prompt + f"\ninput: {text}\noutput:"
|
43 |
+
|
44 |
+
# Generate the response using the pipeline
|
45 |
+
responses = pipe(prompt, max_length=1024, num_return_sequences=1)
|
46 |
+
response_text = responses[0]['generated_text'].split("output:")[-1].strip()
|
47 |
+
|
48 |
+
return response_text if response_text else "No valid response generated."
|
49 |
+
|
50 |
+
except Exception as e:
|
51 |
+
return str(e)
|
52 |
+
|
53 |
+
iface = gr.Interface(
|
54 |
+
fn=generate,
|
55 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
56 |
+
outputs="text",
|
57 |
+
title="Big Data Analytics Assistant",
|
58 |
+
description="Provides concise information about big data analytics across various fields.",
|
59 |
+
live=False
|
60 |
+
)
|
61 |
+
|
62 |
+
def launch_custom_interface():
|
63 |
+
iface.launch()
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
launch_custom_interface()
|