Sugamdeol commited on
Commit
0ff896e
·
verified ·
1 Parent(s): 2970eac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -15
app.py CHANGED
@@ -1,45 +1,132 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
 
3
 
4
  # Set up the client for Mistral model inference
5
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
6
 
7
  def generate_text(prompt):
8
- response = client.text_generation(prompt, max_new_tokens=200, temperature=0.7)
9
  return response
10
 
11
- def generate_argument(topic, stance):
12
- prompt = f"""Generate a compelling argument for the following debate topic.
 
 
 
 
 
 
 
 
13
  Topic: {topic}
14
  Stance: {stance}
15
 
16
- Your response should be a well-structured argument supporting the given stance on the topic."""
 
 
 
 
 
 
 
 
17
  return generate_text(prompt)
18
 
19
- def generate_counterargument(topic, original_argument):
20
- prompt = f"""Generate a strong counterargument for the following debate topic and argument.
21
  Topic: {topic}
22
  Original Argument: {original_argument}
23
 
24
- Your response should be a well-structured counterargument addressing the points made in the original argument."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  return generate_text(prompt)
26
 
27
  def debate_assistant(topic, stance):
28
- argument = generate_argument(topic, stance)
29
- counterargument = generate_counterargument(topic, argument)
30
- return f"Argument:\n{argument}\n\nCounterargument:\n{counterargument}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Create the Gradio interface
33
  iface = gr.Interface(
34
  fn=debate_assistant,
35
  inputs=[
36
- gr.Textbox(label="Debate Topic"),
37
  gr.Radio(["For", "Against"], label="Stance")
38
  ],
39
- outputs=gr.Textbox(label="Generated Debate Arguments"),
40
- title="AI-powered Debate Assistant (Mistral-7B-Instruct-v0.3)",
41
- description="Enter a debate topic and choose a stance to generate arguments and counterarguments using Mistral-7B-Instruct-v0.3."
 
 
 
 
 
42
  )
43
 
44
- # Launch the interface
45
  iface.launch()
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
+ import random
4
 
5
  # Set up the client for Mistral model inference
6
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
7
 
8
  def generate_text(prompt):
9
+ response = client.text_generation(prompt, max_new_tokens=300, temperature=0.7)
10
  return response
11
 
12
+ def categorize_topic(topic):
13
+ prompt = f"""Categorize the following debate topic into one of these categories: Politics, Economics, Technology, Environment, Social Issues, Ethics, or Other.
14
+
15
+ Topic: {topic}
16
+
17
+ Category:"""
18
+ return generate_text(prompt).strip()
19
+
20
+ def generate_structured_argument(topic, stance):
21
+ prompt = f"""Generate a structured argument for the following debate topic.
22
  Topic: {topic}
23
  Stance: {stance}
24
 
25
+ Your response should follow this structure:
26
+ 1. Main claim
27
+ 2. Supporting point 1
28
+ 3. Supporting point 2
29
+ 4. Potential counterargument
30
+ 5. Rebuttal to counterargument
31
+ 6. Conclusion
32
+
33
+ Ensure each point is concise and well-reasoned."""
34
  return generate_text(prompt)
35
 
36
+ def generate_structured_counterargument(topic, original_argument):
37
+ prompt = f"""Generate a structured counterargument for the following debate topic and argument.
38
  Topic: {topic}
39
  Original Argument: {original_argument}
40
 
41
+ Your response should follow this structure:
42
+ 1. Main counter-claim
43
+ 2. Rebuttal to original supporting point 1
44
+ 3. Rebuttal to original supporting point 2
45
+ 4. New supporting point for counter-claim
46
+ 5. Addressing the original rebuttal
47
+ 6. Conclusion
48
+
49
+ Ensure each point directly addresses the original argument and provides new insights."""
50
+ return generate_text(prompt)
51
+
52
+ def assess_argument_quality(argument):
53
+ prompt = f"""Assess the quality of the following argument on a scale of 1 to 10, where 1 is very poor and 10 is excellent. Consider factors such as logical coherence, evidence use, and persuasiveness.
54
+
55
+ Argument: {argument}
56
+
57
+ Provide your assessment in this format:
58
+ Score: [1-10]
59
+ Reasoning: [Brief explanation of the score]"""
60
+ return generate_text(prompt)
61
+
62
+ def generate_sources(topic):
63
+ prompt = f"""Provide a list of 3-5 credible sources that could be used to research the following debate topic:
64
+
65
+ Topic: {topic}
66
+
67
+ For each source, provide:
68
+ 1. Title
69
+ 2. Author or Organization
70
+ 3. Brief description (1-2 sentences)
71
+
72
+ Format the response as a numbered list."""
73
  return generate_text(prompt)
74
 
75
  def debate_assistant(topic, stance):
76
+ category = categorize_topic(topic)
77
+ argument = generate_structured_argument(topic, stance)
78
+ counterargument = generate_structured_counterargument(topic, argument)
79
+ arg_quality = assess_argument_quality(argument)
80
+ counter_quality = assess_argument_quality(counterargument)
81
+ sources = generate_sources(topic)
82
+
83
+ return f"""Topic Category: {category}
84
+
85
+ Argument:
86
+ {argument}
87
+
88
+ Argument Quality Assessment:
89
+ {arg_quality}
90
+
91
+ Counterargument:
92
+ {counterargument}
93
+
94
+ Counterargument Quality Assessment:
95
+ {counter_quality}
96
+
97
+ Suggested Sources for Further Research:
98
+ {sources}"""
99
+
100
+ def suggest_topic():
101
+ topics = [
102
+ "Should artificial intelligence be regulated?",
103
+ "Is universal basic income a viable economic policy?",
104
+ "Should voting be mandatory?",
105
+ "Is space exploration a worthwhile investment?",
106
+ "Should gene editing in humans be allowed?",
107
+ "Is nuclear energy the solution to climate change?",
108
+ "Should social media platforms be held responsible for user content?",
109
+ "Is a four-day work week beneficial for society?",
110
+ "Should animal testing be banned?",
111
+ "Is globalization overall positive or negative for developing countries?"
112
+ ]
113
+ return random.choice(topics)
114
 
115
  # Create the Gradio interface
116
  iface = gr.Interface(
117
  fn=debate_assistant,
118
  inputs=[
119
+ gr.Textbox(label="Debate Topic", placeholder="Enter a topic or click 'Suggest Topic'"),
120
  gr.Radio(["For", "Against"], label="Stance")
121
  ],
122
+ outputs=gr.Textbox(label="Generated Debate Content"),
123
+ title="Advanced AI-powered Debate Assistant",
124
+ description="Enter a debate topic and choose a stance to generate structured arguments, counterarguments, quality assessments, and suggested sources.",
125
+ examples=[
126
+ ["Should artificial intelligence be regulated?", "For"],
127
+ ["Is universal basic income a viable economic policy?", "Against"],
128
+ ["Should gene editing in humans be allowed?", "For"]
129
+ ]
130
  )
131
 
 
132
  iface.launch()